修复重启后自动启动功能

serial
BlueMatthew 1 year ago
parent 8c6b87842c
commit 63064aa857

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

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

@ -24,49 +24,44 @@ public class ScreenActionReceiver extends BroadcastReceiver {
Toast.makeText(context, log, Toast.LENGTH_SHORT).show(); Toast.makeText(context, log, Toast.LENGTH_SHORT).show();
String action = intent.getAction(); 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...");
Log.d(TAG, "screen is on..."); Toast.makeText(context, "screen ON", Toast.LENGTH_SHORT);
Toast.makeText(context,"screen ON",Toast.LENGTH_SHORT);
//Run the locker //Run the locker
context.startService(new Intent(context, FloatingWindow.class));
}
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))
{
Log.d(TAG, "screen is unlock...");
Toast.makeText(context,"screen UNLOCK",Toast.LENGTH_SHORT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, FloatingWindow.class));
} else {
context.startService(new Intent(context, FloatingWindow.class)); context.startService(new Intent(context, FloatingWindow.class));
} } 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_BOOT_COMPLETED.equals(action)){ } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
Log.d(TAG, "boot completed..."); Log.d(TAG, "screen is unlock...");
Toast.makeText(context,"BOOTED..",Toast.LENGTH_SHORT); Toast.makeText(context, "screen UNLOCK", Toast.LENGTH_SHORT);
//Run the locker if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, FloatingWindow.class));
} else {
context.startService(new Intent(context, FloatingWindow.class));
}
} else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
Log.d(TAG, "boot completed...");
Toast.makeText(context, "BOOTED..", Toast.LENGTH_SHORT);
//Run the locker
/* Intent i = new Intent(context, FloatingWindow.class); /* Intent i = new Intent(context, FloatingWindow.class);
context.startService(i); context.startService(i);
*/ */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, FloatingWindow.class)); // context.startForegroundService(new Intent(context, FloatingWindow.class));
} else { } 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" /> <data android:scheme="package" />
</intent-filter> </intent-filter>
</receiver> </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> </application>
</manifest> </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