简体   繁体   English

Android O-android.intent.action.PROVIDER_CHANGED是否受BroadcastRecevier限制影响?

[英]Android O - android.intent.action.PROVIDER_CHANGED affected by BroadcastRecevier limitations?

while reading about the new Android O limitations, I noticed that the Google Devs limited the use of BroadcastReceivers in the manifest. 在阅读有关Android O的新限制时,我注意到Google Devs限制了清单中对BroadcastReceivers的使用。 They use the term implicit and explicit BroadcastReceivers, but I can't quite figure out what they mean exactly. 他们使用了隐式和显式BroadcastReceivers一词,但我不太清楚它们的确切含义。 For example, I have an app which listens to changes in the calender using the android.intent.action.PROVIDER_CHANGED broadcast: 例如,我有一个应用程序,它使用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>

Would this receiver be affected by the new limitations when the app would target Android O? 当应用程序以Android O为目标时,此接收器会受到新限制的影响吗?

Thank you. 谢谢。

They use the term implicit and explicit BroadcastReceivers, but I can't quite figure out what they mean exactly 他们使用隐式和显式BroadcastReceivers一词,但我不太清楚它们的确切含义。

An implicit broadcast is a broadcast of an implicit Intent (eg, sendBroadcast(new Intent(Intent.ACTION_PROVIDER_CHANGED)) ). 隐式广播是隐式Intent的广播(例如sendBroadcast(new Intent(Intent.ACTION_PROVIDER_CHANGED)) )。 An explicit broadcast is a broadcast of an explicit Intent (eg, sendBroadcast(new Intent(this, WhyAreYouDoingThisReceiver.class)) ). 显式广播是显式Intent的广播(例如sendBroadcast(new Intent(this, WhyAreYouDoingThisReceiver.class)) )。

Would this receiver be affected by the new limitations when the app would target Android O? 当应用程序以Android O为目标时,此接收器会受到新限制的影响吗?

It depends entirely on the sender. 这完全取决于发送者。

In Android 7.0, the calendar provider uses this code for sending that broadcast: 在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);
}

That is an implicit broadcast. 那是一个隐式广播。 If the calendar provider does not change on Android O, you will no longer be able to listen to that broadcast in the manifest. 如果日历提供程序未在Android O上更改,则您将不再能够收听清单中的广播。 Your workaround is to use JobScheduler , with a job set to monitor your desired Uri via addContentTriggerUri() on JobInfo.Builder . 解决方法是使用JobScheduler ,将其设置为作业,以通过JobInfo.Builder上的addContentTriggerUri()监视所需的Uri

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM