修复重启后自动启动功能

serial
BlueMatthew 1 year ago
parent 8c6b87842c
commit 63064aa857

@ -1,5 +1,6 @@
package com.xypower.mpapp;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@ -9,14 +10,16 @@ import com.xypower.common.MicroPhotoContext;
public class BootBroadcastReceiver extends BroadcastReceiver {
private static final String ACTION = "android.intent.action.BOOT_COMPLETED";
private static final String TAG = "MPLOG";
@Override
public void onReceive(Context context, Intent intent) {
Log.i("BootBroadcastReceiver", intent.getAction());
Log.i(TAG, intent.getAction());
if (ACTION.equals(intent.getAction())) {
Log.i(TAG, "Start MainActivity");
/*
Intent mainIntent = new Intent(context, MainActivity.class);
@ -28,12 +31,13 @@ public class BootBroadcastReceiver extends BroadcastReceiver {
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
*/
// MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getAppConfig(context);
MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getAppConfig(context);
// MainActivity.startMicroPhotoService(context, appConfig, null);
MainActivity.startMicroPhotoService(context, appConfig, null);
/*
Intent mainIntent = new Intent(context, MainActivity.class);
mainIntent.putExtra("reboot", 1);
//Intent.FLAG_ACTIVITY_NEW_TASK
@ -41,7 +45,6 @@ public class BootBroadcastReceiver extends BroadcastReceiver {
mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mainIntent);
*/
}
}
}

@ -46,7 +46,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
public static final String TAG = "MainActivity";
public static final String TAG = "MPLOG";
private static int MY_PERMISSIONS_REQUEST_FOREGROUND_SERVICE = 100;
public static final int MSG_WHAT_LOG_OBSERVER = MicroPhotoService.MSG_WHAT_MAX + 10;
@ -215,6 +215,7 @@ public class MainActivity extends AppCompatActivity {
int rebootFlag = intent.getIntExtra("reboot", 0);
if (rebootFlag == 1) {
// SysApi.enableAirPlane(MainActivity.this, true);
Log.i(TAG, "After Reboot");
}
Log.d(TAG, "MainActivity: reboot=" + rebootFlag + " noDelay=" + noDelay);

@ -24,26 +24,20 @@ public class ScreenActionReceiver extends BroadcastReceiver {
Toast.makeText(context, log, Toast.LENGTH_SHORT).show();
String action = intent.getAction();
try {
if(Intent.ACTION_SCREEN_ON.equals(action))
{
if (Intent.ACTION_SCREEN_ON.equals(action)) {
Log.d(TAG, "screen is on...");
Toast.makeText(context, "screen ON", Toast.LENGTH_SHORT);
//Run the locker
context.startService(new Intent(context, FloatingWindow.class));
}
else if(Intent.ACTION_SCREEN_OFF.equals(action))
{
} else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
Log.d(TAG, "screen is off...");
Toast.makeText(context, "screen OFF", Toast.LENGTH_SHORT);
}
else if(Intent.ACTION_USER_PRESENT.equals(action))
{
} else if (Intent.ACTION_USER_PRESENT.equals(action)) {
Log.d(TAG, "screen is unlock...");
Toast.makeText(context, "screen UNLOCK", Toast.LENGTH_SHORT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -52,9 +46,7 @@ public class ScreenActionReceiver extends BroadcastReceiver {
context.startService(new Intent(context, FloatingWindow.class));
}
}
else if(Intent.ACTION_BOOT_COMPLETED.equals(action)){
} else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
Log.d(TAG, "boot completed...");
Toast.makeText(context, "BOOTED..", Toast.LENGTH_SHORT);
//Run the locker
@ -63,10 +55,13 @@ public class ScreenActionReceiver extends BroadcastReceiver {
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, FloatingWindow.class));
// context.startForegroundService(new Intent(context, FloatingWindow.class));
} else {
context.startService(new Intent(context, FloatingWindow.class));
// context.startService(new Intent(context, FloatingWindow.class));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

@ -109,6 +109,18 @@
<data android:scheme="package" />
</intent-filter>
</receiver>
<receiver
android:name=".BootBroadcastReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter android:priority="90000">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.REBOOT" />
<category android:name="android.intent.category.default" />
</intent-filter>
</receiver>
</application>
</manifest>

@ -0,0 +1,47 @@
package com.xypower.mpmaster;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BootBroadcastReceiver extends BroadcastReceiver {
private static final String ACTION = "android.intent.action.BOOT_COMPLETED";
private static final String TAG = "MPMasterLOG";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, intent.getAction());
if (ACTION.equals(intent.getAction())) {
Log.i(TAG, "Start MainActivity");
/*
Intent mainIntent = new Intent(context, MainActivity.class);
mainIntent.putExtra("reboot", 1);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
try {
pendingIntent.send();
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
*/
// MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getAppConfig(context);
// MainActivity.startMicroPhotoService(context, appConfig, null);
Intent mainIntent = new Intent(context, MainActivity.class);
mainIntent.putExtra("reboot", 1);
//Intent.FLAG_ACTIVITY_NEW_TASK
// Intent.FLAG_ACTIVITY_CLEAR_TOP
mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mainIntent);
}
}
}
Loading…
Cancel
Save