Android One plus 6(Android pie version) BOOT COMPLETE Broadcast Receiver not working

2518 views android
6

Android One plus 6(Android pie version) BOOT COMPLETE Broadcast Receiver not working

 <receiver
            android:name=".service.ConnectionReceiver"
            android:enabled="true" android:exported="true"
            >
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                <action android:name="android.net.conn.ACTION_BOOT_COMPLETED" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
            </intent-filter>
        </receiver>

below is my reciever class :

public class ConnectionReceiver extends BroadcastReceiver {
 @Override
 public void onReceive(Context context, Intent intent) {
  Log.d("API123", "" + intent.getAction());
  Toast.makeText(context, "isatRunningonbootanyproblem", Toast.LENGTH_SHORT).show();
  context.startService(newIntent(context, IstarBackgroundService.class));
 }
}

I need to start my service once boot get completed. Please suggest what should i do

answered question

Did you add the android.permission.RECEIVE_BOOT_COMPLETED permission to your Manifest?

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> is added

1 Answer

11

This is a special broadcast which you must hold a specific permission in order to receive (from the documentation for ACTION_BOOT_COMPLETED):

You must hold the Manifest.permission.RECEIVE_BOOT_COMPLETED permission in order to receive this broadcast.

Be sure to declare that in your manifest. No runtime permissions are needed since it is a "normal" level permission. However, your app must also get started for the first time by the user (e.g. an Activity in your app) before the system will ever deliver this broadcast to your app.

posted this

Have an answer?

JD

Please login first before posting an answer.