gpt4 book ai didi

android - BroadcastReceiver 不会触发自定义进程名称

转载 作者:行者123 更新时间:2023-11-29 00:12:48 26 4
gpt4 key购买 nike

我尝试监听 Calendar 和 Contacts 事件的变化,所以我创建了 Service 和 BroadcastReceiver,参见 Manifest.xml:

        <service android:name="com.red_folder.phonegap.plugin.backgroundservice.sample.TheService">
<intent-filter>
<action android:name="com.red_folder.phonegap.plugin.backgroundservice.sample.TheService" />
</intent-filter>
</service>
<receiver android:name="com.my.the.TheBroadcastReceiver" android:priority="1000" >
<intent-filter>
<action android:name="android.intent.action.PROVIDER_CHANGED" />
<data android:scheme="content" />
<data android:host="com.android.calendar" />
</intent-filter>
</receiver>
<receiver android:name="com.my.the.BroadcastReceiverContacts" android:priority="1000" >
<intent-filter>
<action android:name="android.intent.action.CONTENT_CHANGED" />
<data android:scheme="content" />
<data android:host="com.android.calendar" />
</intent-filter>
</receiver>

几个小时后,操作系统终止了我的服务,我的应用程序停止监听事件变化。所以我创建了一些 WatchDog:

            <receiver android:name="com.my.the.service.WatcherReceiver" >
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.BATTERY_OKAY" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>

但是当我尝试设置自定义进程名称 (android:process=":theService") 时,它会停止监听。

        <service android:name="com.red_folder.phonegap.plugin.backgroundservice.sample.TheService" android:process=":theService">
<intent-filter>
<action android:name="com.red_folder.phonegap.plugin.backgroundservice.sample.TheService" />
</intent-filter>
</service>
<receiver android:name="com.my.the.TheBroadcastReceiver" android:priority="1000" android:process=":theService">
<intent-filter>
<action android:name="android.intent.action.PROVIDER_CHANGED" />
<data android:scheme="content" />
<data android:host="com.android.calendar" />
</intent-filter>
</receiver>
<receiver android:name="com.my.the.BroadcastReceiverContacts" android:priority="1000" android:process=":theService">
<intent-filter>
<action android:name="android.intent.action.CONTENT_CHANGED" />
<data android:scheme="content" />
<data android:host="com.android.calendar" />
</intent-filter>
</receiver>

<receiver android:name="com.my.the.service.WatcherReceiver" android:process=":serviceWatcher">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.BATTERY_OKAY" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>

如何解决这个问题,

请帮忙,

最佳答案

似乎在单独进程中运行的服务不监听在同一进程中发送的广播,但会在广播是全局时响应。您将必须检查实现情况。我不确定这种行为的确切原因。当您想与服务交互时,最好避免在进程中发送广播。改为发送全局广播。

关于android - BroadcastReceiver 不会触发自定义进程名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28974170/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com