简体   繁体   English

广播接收器几天后停止接收(本地通知)

[英]BroadcastReceiver stops receiving after few days (Local Notification)

I'm using a BroadCastReceiver for triggering alarm which is working fine for like 2-3 days, after that it stops working, I am not receiving any alerts in my BroadcastReceiver. 我正在使用BroadCastReceiver来触发警报,该警报在2-3天内正常工作,在该警报停止工作之后,我的BroadcastReceiver中没有收到任何警报。 Is there a lifeSpan for Pending Intent? 有待定意图的寿命吗? Actually I'm creating alarms for 30 days. 实际上,我正在创建30天的警报。 I'm using PendingIntents. 我正在使用PendingIntents。 Here is the code for PendingIntent: 这是PendingIntent的代码:

PendingIntent pendingIntentScheduler = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);            
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, time, pendingIntentScheduler);

and the receiver at BroadcastReceiver: 和BroadcastReceiver的接收器:

@Override
public void onReceive(Context context, Intent intent) {
     this.context = context;        
     Log.d("onReceive", "this is broadcast reciever");        
}

Android Manifest Permission: Android清单权限:

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
  <application>
  <receiver android:name=".medicine.modal.AlarmReceiver" android:permission="android.permission.WAKE_LOCK"
            android:enabled="true" android:exported="true" android:process=":remote">
            <intent-filter>
                <action android:name="com.healthsaverz.nimap.healthmobile.healthsaverz.mainscreen.controller.NotificationActivity" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
   </application>

I found a solution, not legitimate but a bypass. 我找到了解决方案,不是合法的,而是绕过的。 May be this will help someone. 也许这会帮助某人。 What I did is put a repeating Alarm which repeats at every 24 hours, in which I'm recreating all the Pending Intents. 我所做的是放置一个重复警报,该警报每24小时重复一次,其中我将重新创建所有待处理的意图。 Since the life of pending intent is 2-3 days (According to what i found in my app). 由于待定意图的寿命为2-3天(根据我在应用程序中发现的信息)。 This results in creating new Pending Intents everyday. 这导致每天创建新的待定意向。

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

相关问题 几天后AlarmManager停止工作 - AlarmManager stops working after a few days 手机锁定数小时后,BroadcastReceiver停止工作 - BroadcastReceiver stops working after few hours the phone was locked BroadcastReceiver 未接收本地广播 - BroadcastReceiver is not receiving local broadcast 当应用程序处于前台状态时,Firebase消息在收到推送通知后停止 - Firebase messaging stops after receiving a push notification while app in foreground 几天后在某些新设备中停止在后台接收位置信息,而在其他设备中则可以 - Stop receiving location in background after few days in some new devices meanwhile in others works OK 几秒钟后,使用BroadcastReceiver启动新的活动 - Start new Activity after few seconds with BroadcastReceiver 短信广播接收器在一段时间后停止工作 - SMS BroadcastReceiver stops working after sometime 应用程式停止后,BroadcastReceiver无法运作 - BroadcastReceiver doesn't work after app stops 为什么我的BroadcastReceiver会在一段时间后停止接收 - Why my BroadcastReceiver stop receiving after a while 从broadcastreceiver收到意图后,更改未反映出来 - Changes not reflected after receiving the intent from broadcastreceiver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM