应用关闭或重启设备时未触发Android Alarm Manager

时间:2016-06-29 19:36:59

标签: android android-manifest android-broadcastreceiver

//Alaramkt
public class Alaramkt extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent arg1) {
    // TODO Auto-generated method stub
    Log.e("Location start", "Location startlllllll");
    Intent alarm1 = new Intent(context, LocationReceiver.class);
    boolean alarmRunning1 = (PendingIntent.getBroadcast(context, 0, alarm1,
            PendingIntent.FLAG_NO_CREATE) != null);
if (alarmRunning1 == false) {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
                0, alarm1, 0);
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
                SystemClock.elapsedRealtime(), 5000, pendingIntent);

    }
}

}



//Location receiver


public class LocationReceiver extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Log.e("Location start", "Location start");
    System.gc();
    Intent background = new Intent(context, BackgroundReceiverService.class);
    context.startService(background);
}


}


//Manifestfile

   <receiver android:name="com.main.service.LocationReceiver" >
    </receiver>  


    <receiver
    android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
    android:enabled="true"
    android:exported="true"
    android:process=":remote"
    android:name="com.main.service.Alaramkt">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="Alaramkt"/>
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>




    <receiver  android:process=":remote" android:name="com.main.service.Alaramkt"></receiver>

   // 

这里缺少上面的代码。一旦应用程序关闭(这意味着堆空间删除应用程序)和设备重新启动后不工作接收器

0 个答案:

没有答案