version:2.0.1.5_release

update:2020.07.07
fix:修复自动更新有个app之后,另外一个无法调起来,使用广播在安装应用和锁屏之后调起另一个应用
add:
This commit is contained in:
2020-07-07 17:29:46 +08:00
parent 3f400f763d
commit d6857d576c
7 changed files with 85 additions and 17 deletions

View File

@@ -2,6 +2,7 @@ package com.mjsheng.myappstore;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -39,8 +40,11 @@ import com.mjsheng.myappstore.jpush.TagAliasOperatorHelper;
import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.network.Network;
import com.mjsheng.myappstore.network.api.newapi.GetLockState;
import com.mjsheng.myappstore.receiver.BootReceiver;
import com.mjsheng.myappstore.receiver.NewAppReceiver;
import com.mjsheng.myappstore.server.GuardService;
import com.mjsheng.myappstore.server.InitJpushServer;
import com.mjsheng.myappstore.server.MyDownloadService;
import com.mjsheng.myappstore.server.StepService;
import com.mjsheng.myappstore.utils.Configure;
import com.mjsheng.myappstore.utils.MySQLData;
@@ -101,6 +105,7 @@ public class MyApplication extends MultiDexApplication {
private SimpleDateFormat mDateFormat = null;
private static List<Activity> activityList = new LinkedList();
public static Context getAppContext() {
return context;
}
@@ -156,10 +161,16 @@ public class MyApplication extends MultiDexApplication {
if (!BuildConfig.DEBUG) {
catchException();
}
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//8.0之后需要在
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// 8.0之后需要在
registmNewAppReceiver();
startService(new Intent(this, InitJpushServer.class));
startService(new Intent(this, StepService.class));
startService(new Intent(this, GuardService.class));
startService(new Intent(this, MyDownloadService.class));
}
registerTimeReceiver();
// }
ignoreBatteryOptimization(this);
}
@@ -182,8 +193,17 @@ public class MyApplication extends MultiDexApplication {
}
}
}
private NewAppReceiver mNewAppReceiver;
private receiver receiver;
private void registmNewAppReceiver() {
mNewAppReceiver = new NewAppReceiver();
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
registerReceiver(mNewAppReceiver, filter);
}
//监听时间和日期变化
public void registerTimeReceiver() {
@@ -197,6 +217,8 @@ public class MyApplication extends MultiDexApplication {
registerReceiver(receiver, filter);
}
private receiver receiver;
Long time1 = 0L;
Long time2 = 0L;
@@ -211,6 +233,17 @@ public class MyApplication extends MultiDexApplication {
getLockState("2", String.valueOf(time));
} else if (action.equals(Intent.ACTION_USER_PRESENT)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
/*在8.0以上 除了开机广播其他广播基本上没有用
*当静默安装升级时app不会被唤醒只有通过显示广播唤醒
* */
Intent intent1 = new Intent(BootReceiver.BOOT_COMPLETED);
intent1.setComponent(new ComponentName("com.jiaoguanyi.store", "com.mjsheng.myappstore.receiver.BootReceiver"));
// 携带数据
// intent1.putExtra("test", "我是来测 A 应用的Android 8.0 系统静态广播的测试数据");
// 启动发送广播
sendBroadcast(intent1);
time2 = System.currentTimeMillis();
if ((time2 - time1) > 60 * 1000) {
//可能会多次触发1分钟之内不执行
@@ -224,6 +257,11 @@ public class MyApplication extends MultiDexApplication {
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
long time = System.currentTimeMillis();
getLockState("1", String.valueOf(time));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Intent intent1 = new Intent(BootReceiver.BOOT_COMPLETED);
intent1.setComponent(new ComponentName("com.jiaoguanyi.store", "com.mjsheng.myappstore.receiver.BootReceiver"));
sendBroadcast(intent1);
}
}
}