android.intent.action.BOOT_COMPLETED Intent is not

2020-02-25 08:11发布

Android android.intent.action.BOOT_COMPLETED Intent is not received if I use the "Restart" or "Reboot", but works if I turn off and on the device. Is there Any way to make this work?

3条回答
一纸荒年 Trace。
2楼-- · 2020-02-25 08:37

Add

<action android:name="android.intent.action.QUICKBOOT_POWERON" /> 

also

查看更多
在下西门庆
3楼-- · 2020-02-25 08:42

Kindly add the below Permission:

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

and add the Receiver Class entry in manifest.zml:

<receiver android:name="com.example.receivers.BootReceiver" >

Now Receiver Class:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class BootReceiver extends BroadcastReceiver {

  private static final String TAG = "Boot Receiver:::";
   /*
    * (non-Javadoc)
    * 
    * @see android.content.BroadcastReceiver#onReceive(android.content.Context,
    * android.content.Intent)
    */
    @Override
    public void onReceive(Context context, Intent intent) {
      if (intent != null) {
        if (intent.getAction().equalsIgnoreCase(
                Intent.ACTION_BOOT_COMPLETED)) {

            //Boot Receiver Called
        }
      }
    }
 }

Now Clean and Run your Application. Hope This class will be called after you power on/off or restarting the device. let me know your feedback.

查看更多
欢心
4楼-- · 2020-02-25 08:46

Add <action android:name="android.intent.action.QUICKBOOT_POWERON" /> this permission in manifest file.

查看更多
登录 后发表回答