奥利奥,默认短信应用和ACTION_RESPOND_VIA_MESSAGE

时间:2018-01-11 10:45:09

标签: java android android-intent service android-intentservice

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

作为默认SMS应用程序的要求之一是:(来自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权限的服务,如果我们在应用程序处于后台时收到电话,并且用户拒绝拨打该短信,则服务将无法启动。

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

知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

对于普通的android情况并非如此,因为默认实现不会调用SMS App来拒绝具有消息和用法SmsManager的呼叫。

来自AOSP oreo中RespondViaSmsManager.java的引用

Selector

似乎有些oems(我曾用oneplus体验过)自定义了此选项,并保持了较旧的行为,这需要启动SMS应用程序服务。无需记住-- extension: ScopedTypeVariables, TypeFamilies -- the type equality (a ~ String) is for better error messages when -- a record has a field not of type String instance (a ~ String, Selector s) => GFromMap (M1 S s (K1 i a)) where gFromMap m = M1 <$> K1 <$> Map.lookup fdName m where fdName = toUpper <$> selName (undefined :: _t s _r _a) -- we can refer to s thanks to ScopedTypeVariables 中涉及后台服务的情况。

以下是一些抱怨:

  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应用程序上都遇到了这种情况,包括Google在Android 8.1上的oneplus 5上从Messages上获取了

这仍然不能解释OEM如何在同一设备上为该用例提供Microsoft提供的短信应用或Microsoft的SMS Organizer