Android O - android.intent.action.PROVIDER_CHANGED受BroadcastRecevier限制?

时间:2017-06-15 07:31:16

标签: android broadcastreceiver android-8.0-oreo

在阅读新的Android O限制时,我注意到Google Devs限制了清单中BroadcastReceivers的使用。他们使用术语隐式和显式BroadcastReceivers,但我无法弄清楚它们究竟是什么意思。例如,我有一个应用程序,它使用 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时,此接收器是否会受到新限制的影响?

谢谢。

1 个答案:

答案 0 :(得分:5)

  

他们使用术语隐式和显式BroadcastReceivers,但我无法弄清楚它们的确切含义

隐式广播是隐式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,并将作业集设置为通过Uri上的addContentTriggerUri()来监控您所需的JobInfo.Builder