0

I am testing a very basic app for getting Boot_Completed broadcast on device reboot. I am testing app on android 10 OPPO device Following is my code

Manifest.xml

  <receiver android:name=".SampleBootReceiver" android:enabled="true" android:exported="true">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT"/>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
            <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
            <!--For HTC devices-->
            <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
        </intent-filter>
    </receiver>

SampleBootReceiver.java

public class SampleBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Log.e("MyApp", " Boot completed fired");
    Toast.makeText(context, "fired " , Toast.LENGTH_LONG).show();
    if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")){
        Log.e("MyApp", "matches intent");
    }
}
}

My application didn't receiving Boot_Completed broadcast on device reboot.

NOTE - If i start the app manually just after device reboot, then i am getting broadcast in my app and able to see logs in logcat. But when i didn't start app after device reboot, nothing print in logcat.

I even tried putting showing toast on receiving broadcast, nothing happens.

Please suggest !

Rajeev Kumar
  • 4,901
  • 8
  • 48
  • 83
  • Have you enabled auto start permission for your app from settings – Nitish Oct 01 '21 at 08:01
  • @Nitish i have added only this permission in manifest `` – Rajeev Kumar Oct 01 '21 at 08:04
  • You have to enable autostart for your app in device settings. – Praveen Oct 01 '21 at 08:11
  • Please see how to [enable auto start from settings](https://www.techbone.net/oppo/user-manual/autostart) or you can you can do it [programmatically](https://stackoverflow.com/questions/44383983/how-to-programmatically-enable-auto-start-and-floating-window-permissions) – Nitish Oct 01 '21 at 08:28

0 Answers0