android - My app can't receive BOOT_COMPLETED broadcast -


i working on app needs receive boot_completed broadcast when device boots. according documents in android developers, know since android 3.1, apps never run after installing or force killed user not receive boot broadcast when device boots, rules, how can receive boot broadcast? way, have tried open app when boot finished, still not working.

here's code:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"           package="com.guoyonghui.todo"           android:installlocation="auto">      <uses-permission android:name="android.permission.vibrate"/>     <uses-permission android:name="android.permission.wake_lock"/>     <uses-permission android:name="android.permission.receive_boot_completed"/>      <application         android:name=".baseapplication"         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:supportsrtl="true"         android:theme="@style/apptheme">         <activity android:name=".tasks.tasksactivity">             <intent-filter>                 <action android:name="android.intent.action.main"/>                  <category android:name="android.intent.category.launcher"/>             </intent-filter>         </activity>         <activity android:name=".taskdetail.taskdetailactivity"/>         <activity android:name=".addedittask.addedittaskactivity"/>         <activity android:name=".statistics.statisticsactivity"/>          <receiver android:name=".alarm.alarmreceiver">             <intent-filter>                 <action android:name="com.guoyonghui.todo.alarm.action_task_alarm"/>             </intent-filter>         </receiver>         <receiver             android:name=".alarm.bootreceiver"             android:enabled="true">             <intent-filter>                 <action android:name="android.intent.action.boot_completed"/>                 <action android:name="android.intent.category.default"/>             </intent-filter>         </receiver>     </application>  </manifest>  public class bootreceiver extends broadcastreceiver {      @override     public void onreceive(context context, intent intent) {         string action = intent.getaction();          toast.maketext(context, action, toast.length_short).show();         log.d("alarmreceiver", action);          if (intent.action_boot_completed.equals(action)) {             tasksrepository tasksrepository = tasksrepository.getinstance(taskslocaldatasource.getinstance(context));             list<task> tasks = tasksrepository.loadtasks();             (task task : tasks) {                 if (task.isactive()) {                     alarmreceiver.setalarm(context, task);                 }             }         }     } } 

you don't want use default category in case. according documentation of category, used following purpose:

set if activity should option default action (center press) perform on piece of data. setting hide user activities without set when performing action on data. note -not- set in intent when initiating action -- use in intent filters specified in packages. (emphasis mine)

see list of categories , they're here: https://developer.android.com/reference/android/content/intent.html


Comments