1

在阅读新的 Android O 限制时,我注意到 Google 开发人员限制了清单中广播接收器的使用。他们使用术语隐式和显式广播接收器,但我不太清楚它们的确切含义。例如,我有一个应用程序使用android.intent.action.PROVIDER_CHANGED广播监听日历中的变化:

<receiver
    android:name=".receivers.CalendarReceiver">
    <intent-filter>
        <action android:name="android.intent.action.PROVIDER_CHANGED"/>

        <data android:scheme="content"/>
        <data android:host="com.android.calendar"/>
    </intent-filter>
</receiver>

当应用程序以 Android O 为目标时,此接收器是否会受到新限制的影响?

谢谢你。

4

1 回答 1

7

他们使用术语隐式和显式广播接收器,但我不太清楚它们的确切含义

隐式广播是隐式Intent(例如,sendBroadcast(new Intent(Intent.ACTION_PROVIDER_CHANGED)))的广播。显式广播是显式广播Intent(例如,sendBroadcast(new Intent(this, WhyAreYouDoingThisReceiver.class)))。

当应用程序以 Android O 为目标时,此接收器是否会受到新限制的影响?

这完全取决于发件人。

在 Android 7.0 中,日历提供程序使用以下代码发送该广播:

private void doSendUpdateNotification() {
    Intent intent = new Intent(Intent.ACTION_PROVIDER_CHANGED,
            CalendarContract.CONTENT_URI);
    intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
    if (Log.isLoggable(TAG, Log.INFO)) {
        Log.i(TAG, "Sending notification intent: " + intent);
    }
    mContext.sendBroadcast(intent, null);
}

那是隐式广播。如果 Android O 上的日历提供程序未更改,您将无法再在清单中收听该广播。您的解决方法是使用JobScheduler,通过设置来监视您想要UriaddContentTriggerUri()工作JobInfo.Builder

于 2017-06-15T10:59:51.920 回答