1.首先继承一个broadcastreceiver

public class ConnectBroadCastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
         if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
                Intent bootActivityIntent=new Intent(context,MainActivity.class);
                bootActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(MainActivity);//要启动应用程序的首界面
            }
    }

}

2.在AndroidMenifest.xml中配置Receiver

<receiver android:name=".BootBroadcastReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"></action>
    </intent-filter>
</receiver>

3.添加权限

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

 

相关文章:

  • 2021-09-22
  • 2021-07-04
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
猜你喜欢
  • 2021-12-07
  • 2022-12-23
  • 2021-07-31
  • 2021-11-23
  • 2021-11-01
  • 2021-04-26
相关资源
相似解决方案