public class BroadCast extends BroadcastReceiver {

private static final String Action="android.intent.action.BOOT_COMPLETED";

@Override
public void onReceive(Context contextIntent intent) {
if (intent.getAction().equals(Action))
{

// Intent MyScene=new Intent(context, com.slq.myapp.MyScene.class);
// MyScene.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Intent MyScene=context.getPackageManager().getLaunchIntentForPackage("com.slq.myapp");

context.startActivity(MyScene);
}

}

}   

一定要把BroadCast类建在com.Slq.xxx下边,不能建在Java目录下,否则的话会开机自启的时候出错。                                                                         

      Android开机自启                                                                                                                           

 

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.slq.myapp">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MyScene">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

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

</intent-filter>
</receiver>

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


Android开机自启

相关文章:

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