Browse Source

增加开机自启动

plate
fyf 8 months ago
parent
commit
9b316e5bcd
2 changed files with 26 additions and 0 deletions
  1. +11
    -0
      app/src/main/AndroidManifest.xml
  2. +15
    -0
      app/src/main/java/com/bpa/scalage/app/BootReceiver.java

+ 11
- 0
app/src/main/AndroidManifest.xml View File

@@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<uses-feature android:name="android.hardware.usb.host" />

@@ -32,6 +33,16 @@
android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden|navigation"
android:label="@string/app_name"></activity>

<receiver
android:name=".app.BootReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />

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

</manifest>

+ 15
- 0
app/src/main/java/com/bpa/scalage/app/BootReceiver.java View File

@@ -0,0 +1,15 @@
package com.bpa.scalage.app;

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

public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Intent toIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
context.startActivity(toIntent);
}
}
}

Loading…
Cancel
Save