0

我有一个每 5 分钟左右触发一次的服务...我将如何查询 android 以查看该服务何时以编程方式关闭?

    <!-- Send Census Service -->
    <service android:name="services.scheduled.SendCensusScheduledService"
             android:icon="@drawable/ic_launcher"
             android:label="SyncServerDataScheduledService" />
    <receiver android:name="services.receivers.SendCensusScheduledServiceReceiver" >
        <intent-filter>
            <action android:name="ReceiptBucketClient.android.action.broadcast"/>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <receiver android:name="services.receivers.StartSendCensusScheduledServiceReceiver" />
4

1 回答 1

0

通过以下方式检查PendingIntent

PendingIntent intent = PendingIntent.getBroadcast(context, 0, 
        new Intent("ReceiptBucketClient.android.action.broadcast"), 
        PendingIntent.FLAG_NO_CREATE;

if (intent != null) {
   // you have the service scheduled. Cancel it!
   intent.cancel();
}

请记住,只有拥有 PendingIntent 的原始应用程序才能取消它。

于 2015-04-23T02:31:47.763 回答