奥利奥(Oreo),默认短信应用和ACTION_RESPOND_VIA_MESSAGE [英] Oreo, default SMS App and ACTION_RESPOND_VIA_MESSAGE

查看:183
本文介绍了奥利奥(Oreo),默认短信应用和ACTION_RESPOND_VIA_MESSAGE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

针对Android O的应用程序在使用服务时有一些新规则,其中之一是我们无法在后台运行应用程序时启动服务.

Applications targeting Android O have a couple of new rules when using services, one of them is that we can't start services while the application is in background.

默认的SMS应用程序的要求之一是:(来自Telephony.java javadoc)

One of the requirements to be a default SMS application is: (from the Telephony.java javadoc)

* <li>In a service, include an intent filter for {@link
* android.telephony.TelephonyManager#ACTION_RESPOND_VIA_MESSAGE}
* (<code>"android.intent.action.RESPOND_VIA_MESSAGE"</code>) with schemas,
* <code>sms:</code>, <code>smsto:</code>, <code>mms:</code>, and <code>mmsto:</code>.
* This service must also require the {@link
* android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE} permission.
* <p>This allows users to respond to incoming phone calls with an immediate text message
* using your app.</p></li>
* </ul>

您可以看到我的问题...,如果ACTION_RESPOND_VIA_MESSAGE需要具有SEND_RESPOND_VIA_MESSAGE权限的服务,如果我们在应用程序处于后台的状态下接到电话,而用户以短信拒绝通话,则该服务将无法启动.

You can see my problem... because ACTION_RESPOND_VIA_MESSAGE needs a service with permission SEND_RESPOND_VIA_MESSAGE if we receive a phone call while the application is in background and the user rejects the call with a text message the service will fail to start.

1237-6018 W/Binder: Binder call failed.
                    java.lang.IllegalStateException: Not allowed to start service Intent { act=android.intent.action.RESPOND_VIA_MESSAGE dat=smsto:xxxxxxxxx cmp=APP_PACKAGE_NAME (has extras) }: app is in background uid null

您知道如何解决此问题吗?

Any idea how to fix this issue?

推荐答案

股票android不应该这样,因为默认实现不会调用SMS App来拒绝带有消息和用法SmsManager的呼叫.

This shouldn't be the case with stock android, as default implementation does not call SMS App to reject calls with message and usage SmsManager instead.

引用"rel =" nofollow noreferrer"> AOSP oreo中的> RespondViaSmsManager.java

reference from RespondViaSmsManager.java in AOSP oreo

/**
 * Reject the call with the specified message. If message is null this call is ignored.
 */
private void rejectCallWithMessage(Context context, String phoneNumber, String textMessage,
                                   int subId, String contactName) {
    if (TextUtils.isEmpty(textMessage)) {
        Log.w(RespondViaSmsManager.this, "Couldn't send SMS message: empty text message. ");
        return;
    }
    if (!SubscriptionManager.isValidSubscriptionId(subId)) {
        Log.w(RespondViaSmsManager.this, "Couldn't send SMS message: Invalid SubId: " +
                subId);
        return;
    }

    SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
    try {
        smsManager.sendTextMessage(phoneNumber, null, textMessage, null /*sentIntent*/,
                null /*deliveryIntent*/);

        SomeArgs args = SomeArgs.obtain();
        args.arg1 = !TextUtils.isEmpty(contactName) ? contactName : phoneNumber;
        args.arg2 = context;
        mHandler.obtainMessage(MSG_SHOW_SENT_TOAST, args).sendToTarget();
    } catch (IllegalArgumentException e) {
        Log.w(RespondViaSmsManager.this, "Couldn't send SMS message: " +
                e.getMessage());
    }
}

似乎有些oems(我曾用oneplus体验过)自定义了此选项,并保持了较旧的行为,这需要启动SMS应用程序的服务.无需记住oreo中与后台服务有关的限制.

seems like some oems (I have experianced this with oneplus) customized this and kept older behaviour which requires starting the service of SMS app. without keeping in mind that there are limatations in oreo with respect to background services.

以下是一些抱怨:

  1. > https://www.reddit.com/r/oneplus/评论/8n9w37/cant_send_text_message_when_rejecting_phone_call/
  1. https://www.reddit.com/r/oneplus/comments/8n9w37/cant_send_text_message_when_rejecting_phone_call/
  2. https://forums.oneplus.com/threads/reject-call-with-sms-is-not-working-after-oreo-update-oxygen-5-0-1-3t.817578/

我在大多数SMS应用程序上都遇到了这种情况,包括

I have experianced this behaviour on most of the SMS apps, including Messages from google on oneplus 5 with android version 8.1

这仍然不能解释OEM如何提供短信应用或

This still doesn't explain how OEM provided sms app or SMS Organizer from microsoft works for this use case on same device.

这篇关于奥利奥(Oreo),默认短信应用和ACTION_RESPOND_VIA_MESSAGE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆