update:2019.12.03
fix: add:app强制弹窗更新
This commit is contained in:
@@ -115,7 +115,7 @@ dependencies {
|
|||||||
|
|
||||||
implementation 'com.github.bumptech.glide:glide:4.10.0'
|
implementation 'com.github.bumptech.glide:glide:4.10.0'
|
||||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
|
||||||
//aria
|
//aria
|
||||||
implementation 'com.arialyy.aria:core:3.7.7'
|
implementation 'com.arialyy.aria:core:3.7.7'
|
||||||
annotationProcessor 'com.arialyy.aria:compiler:3.7.7'
|
annotationProcessor 'com.arialyy.aria:compiler:3.7.7'
|
||||||
//OKGO
|
//OKGO
|
||||||
|
|||||||
@@ -70,11 +70,12 @@
|
|||||||
android:name=".receiver.AppManagerReceiver"
|
android:name=".receiver.AppManagerReceiver"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter android:priority="1000">
|
<intent-filter android:priority="10000">
|
||||||
<action android:name="android.intent.action.PACKAGE_ADDED" />
|
<action android:name="android.intent.action.PACKAGE_ADDED" />
|
||||||
<action android:name="android.intent.action.PACKAGE_REPLACED" />
|
<action android:name="android.intent.action.PACKAGE_REPLACED" />
|
||||||
<action android:name="android.intent.action.PACKAGE_REMOVED" />
|
<action android:name="android.intent.action.PACKAGE_REMOVED" />
|
||||||
|
<action android:name="android.intent.action.USER_PRESENT" />
|
||||||
|
<action android:name="android.intent.action.BATTERY_CHANGED" />
|
||||||
<data android:scheme="package" />
|
<data android:scheme="package" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import androidx.fragment.app.Fragment;
|
|||||||
import androidx.fragment.app.FragmentPagerAdapter;
|
import androidx.fragment.app.FragmentPagerAdapter;
|
||||||
import androidx.viewpager.widget.ViewPager;
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
|
import com.appstore.uiui.BuildConfig;
|
||||||
import com.appstore.uiui.R;
|
import com.appstore.uiui.R;
|
||||||
import com.appstore.uiui.base.BaseActivity;
|
import com.appstore.uiui.base.BaseActivity;
|
||||||
import com.appstore.uiui.base.UserInfo;
|
import com.appstore.uiui.base.UserInfo;
|
||||||
@@ -33,6 +34,7 @@ import com.appstore.uiui.jpush.LocalBroadcastManager;
|
|||||||
import com.appstore.uiui.jpush.TagAliasOperatorHelper;
|
import com.appstore.uiui.jpush.TagAliasOperatorHelper;
|
||||||
import com.appstore.uiui.network.OKGOPost;
|
import com.appstore.uiui.network.OKGOPost;
|
||||||
import com.appstore.uiui.service.MyDownloadService;
|
import com.appstore.uiui.service.MyDownloadService;
|
||||||
|
import com.appstore.uiui.utils.ApkUtils;
|
||||||
import com.appstore.uiui.utils.LogUtils;
|
import com.appstore.uiui.utils.LogUtils;
|
||||||
import com.appstore.uiui.utils.SPUtils;
|
import com.appstore.uiui.utils.SPUtils;
|
||||||
import com.appstore.uiui.utils.ToastUtil;
|
import com.appstore.uiui.utils.ToastUtil;
|
||||||
@@ -41,6 +43,10 @@ import com.flyco.tablayout.SlidingTabLayout;
|
|||||||
import com.hjq.permissions.OnPermission;
|
import com.hjq.permissions.OnPermission;
|
||||||
import com.hjq.permissions.Permission;
|
import com.hjq.permissions.Permission;
|
||||||
import com.hjq.permissions.XXPermissions;
|
import com.hjq.permissions.XXPermissions;
|
||||||
|
import com.lzy.okgo.OkGo;
|
||||||
|
import com.lzy.okgo.callback.FileCallback;
|
||||||
|
import com.lzy.okgo.model.Progress;
|
||||||
|
import com.lzy.okgo.model.Response;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -86,7 +92,7 @@ public class MainActivity extends BaseActivity {
|
|||||||
// PackageManager pm = getPackageManager();
|
// PackageManager pm = getPackageManager();
|
||||||
// pm.setApplicationEnabledSetting("com.tencent.qqmusic", PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
|
// pm.setApplicationEnabledSetting("com.tencent.qqmusic", PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
|
||||||
startService(new Intent(MainActivity.this, MyDownloadService.class));
|
startService(new Intent(MainActivity.this, MyDownloadService.class));
|
||||||
|
CheckUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -147,6 +153,10 @@ public class MainActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synchronized private void CheckUpdate() {
|
||||||
|
OKGOPost.checkUpdateByPackage(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化 JPush。如果已经初始化,但没有登录成功,则执行重新登录。
|
// 初始化 JPush。如果已经初始化,但没有登录成功,则执行重新登录。
|
||||||
private void init() {
|
private void init() {
|
||||||
JPushInterface.init(getApplicationContext());
|
JPushInterface.init(getApplicationContext());
|
||||||
@@ -359,7 +369,35 @@ public class MainActivity extends BaseActivity {
|
|||||||
case 2:
|
case 2:
|
||||||
SPUtils.put(MainActivity.this, "isLogined", 2);
|
SPUtils.put(MainActivity.this, "isLogined", 2);
|
||||||
break;
|
break;
|
||||||
|
case 200:
|
||||||
|
String url = (String) msg.obj;
|
||||||
|
getFile(url);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private void getFile(String url) {
|
||||||
|
OkGo.<File>get(url)
|
||||||
|
.execute(new FileCallback() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Response<File> response) {
|
||||||
|
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
||||||
|
ApkUtils.installApkInSilence(response.body().getAbsolutePath(), MainActivity.this.getPackageName());
|
||||||
|
LogUtils.e("getFile", "download file successful,now installing");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Response<File> response) {
|
||||||
|
super.onError(response);
|
||||||
|
LogUtils.e("getFile", "File download Failure");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downloadProgress(Progress progress) {
|
||||||
|
super.downloadProgress(progress);
|
||||||
|
LogUtils.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class OKGOPost {
|
|||||||
@Override
|
@Override
|
||||||
public void onError(Response<String> response) {
|
public void onError(Response<String> response) {
|
||||||
super.onError(response);
|
super.onError(response);
|
||||||
LogUtils.e("onError", response.getException().toString());
|
LogUtils.e("getAllAppInfo", response.getException().toString());
|
||||||
ToastUtil.show("网络连接失败,检查网络连接");
|
ToastUtil.show("网络连接失败,检查网络连接");
|
||||||
handler.sendEmptyMessage(0);
|
handler.sendEmptyMessage(0);
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ public class OKGOPost {
|
|||||||
@Override
|
@Override
|
||||||
public void onError(Response<String> response) {
|
public void onError(Response<String> response) {
|
||||||
super.onError(response);
|
super.onError(response);
|
||||||
LogUtils.e("onError", response.getException().toString());
|
LogUtils.e("getRankApp", response.getException().toString());
|
||||||
ToastUtil.show("网络连接失败,检查网络连接");
|
ToastUtil.show("网络连接失败,检查网络连接");
|
||||||
handler.sendEmptyMessage(0);
|
handler.sendEmptyMessage(0);
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ public class OKGOPost {
|
|||||||
@Override
|
@Override
|
||||||
public void onError(Response<String> response) {
|
public void onError(Response<String> response) {
|
||||||
super.onError(response);
|
super.onError(response);
|
||||||
LogUtils.e("onError", response.getException().toString());
|
LogUtils.e("searchAppbyName", response.getException().toString());
|
||||||
ToastUtil.show("网络连接失败,检查网络连接");
|
ToastUtil.show("网络连接失败,检查网络连接");
|
||||||
handler.sendEmptyMessage(0);
|
handler.sendEmptyMessage(0);
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ public class OKGOPost {
|
|||||||
@Override
|
@Override
|
||||||
public void onError(Response<String> response) {
|
public void onError(Response<String> response) {
|
||||||
super.onError(response);
|
super.onError(response);
|
||||||
LogUtils.e("onError", response.getException().toString());
|
LogUtils.e("getUserInfo", response.getException().toString());
|
||||||
ToastUtil.show("网络连接失败,检查网络连接");
|
ToastUtil.show("网络连接失败,检查网络连接");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -220,7 +220,7 @@ public class OKGOPost {
|
|||||||
@Override
|
@Override
|
||||||
public void onError(Response<String> response) {
|
public void onError(Response<String> response) {
|
||||||
super.onError(response);
|
super.onError(response);
|
||||||
LogUtils.e("onError", response.getException().toString());
|
LogUtils.e("getUserInfo", response.getException().toString());
|
||||||
ToastUtil.show("网络连接失败,检查网络连接");
|
ToastUtil.show("网络连接失败,检查网络连接");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -255,7 +255,7 @@ public class OKGOPost {
|
|||||||
@Override
|
@Override
|
||||||
public void onError(Response<String> response) {
|
public void onError(Response<String> response) {
|
||||||
super.onError(response);
|
super.onError(response);
|
||||||
LogUtils.e("onError", response.getException().toString());
|
LogUtils.e("getSortApp", response.getException().toString());
|
||||||
ToastUtil.show("网络连接失败,检查网络连接");
|
ToastUtil.show("网络连接失败,检查网络连接");
|
||||||
handler.sendEmptyMessage(0);
|
handler.sendEmptyMessage(0);
|
||||||
}
|
}
|
||||||
@@ -319,6 +319,44 @@ public class OKGOPost {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synchronized public static void checkUpdateByPackage(final Handler handler, String packageName, String versionCode) {
|
||||||
|
OkGo.<String>post(Url.GET_APP_UPDATE)
|
||||||
|
.params("code", versionCode)
|
||||||
|
.params("package", packageName)
|
||||||
|
.execute(new StringCallback() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Response<String> response) {
|
||||||
|
try {
|
||||||
|
JSONObject body = JSON.parseObject(response.body());
|
||||||
|
int code = body.getInteger("code");
|
||||||
|
String msg = body.getString("msg");
|
||||||
|
if (code == 200) {
|
||||||
|
Message message = new Message();
|
||||||
|
JSONObject data = JSON.parseObject(body.getString("data"));
|
||||||
|
if (data != null) {
|
||||||
|
String url = data.getString("downloadurl");
|
||||||
|
message.what = 200;
|
||||||
|
message.obj = url;
|
||||||
|
} else {
|
||||||
|
message.what = -200;
|
||||||
|
}
|
||||||
|
handler.sendMessage(message);
|
||||||
|
} else {
|
||||||
|
Log.e("checkUpdateByPackage", msg);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("checkUpdateByPackage", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Response<String> response) {
|
||||||
|
super.onError(response);
|
||||||
|
Log.e("checkUpdateByPackage", response.getException().toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,5 +17,6 @@ public class Url {
|
|||||||
//发送app安装信息
|
//发送app安装信息
|
||||||
public final static String SET_APP_UNINSTALL_INFO = NETWORK_HOME_ADDRESS + "/App/appUnload";
|
public final static String SET_APP_UNINSTALL_INFO = NETWORK_HOME_ADDRESS + "/App/appUnload";
|
||||||
//发送app卸载信息
|
//发送app卸载信息
|
||||||
|
public final static String GET_APP_UPDATE = NETWORK_HOME_ADDRESS + "/Update/update";
|
||||||
|
//根据包名获取更新
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,21 +14,22 @@ import com.appstore.uiui.utils.ToastUtil;
|
|||||||
|
|
||||||
public class AppManagerReceiver extends BroadcastReceiver {
|
public class AppManagerReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
private static final String TAG = "--AppManagerReceiver--";
|
private static final String TAG = "AppManagerReceiver";
|
||||||
private String action = null;
|
private String action = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
int member_id = (int) SPUtils.get(context, "member_id", -1);
|
int member_id = (int) SPUtils.get(context, "member_id", -1);
|
||||||
String sn_id = (String) SPUtils.get(context, "sn_id", "-1");
|
String sn_id = (String) SPUtils.get(context, "sn_id", "-1");
|
||||||
|
Log.e("BootReceiver", intent.getAction());
|
||||||
|
|
||||||
action = intent.getAction();
|
action = intent.getAction();
|
||||||
//接收安装广播
|
//接收安装广播
|
||||||
if (action.equals(Intent.ACTION_PACKAGE_ADDED) || action.equals(Intent.ACTION_PACKAGE_REPLACED)) {
|
if (action.equals(Intent.ACTION_PACKAGE_ADDED) || action.equals(Intent.ACTION_PACKAGE_REPLACED)) {
|
||||||
if (action.equals(Intent.ACTION_PACKAGE_ADDED)){
|
if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {
|
||||||
Intent intents = new Intent("com.appstore.uiui.PACKAGE_ADDED");
|
Intent intents = new Intent("com.appstore.uiui.PACKAGE_ADDED");
|
||||||
context.sendBroadcast(intents);
|
context.sendBroadcast(intents);
|
||||||
}else {
|
} else {
|
||||||
Intent intents = new Intent("com.appstore.uiui.PACKAGE_REPLACED");
|
Intent intents = new Intent("com.appstore.uiui.PACKAGE_REPLACED");
|
||||||
context.sendBroadcast(intents);
|
context.sendBroadcast(intents);
|
||||||
}
|
}
|
||||||
@@ -37,7 +38,7 @@ public class AppManagerReceiver extends BroadcastReceiver {
|
|||||||
ToastUtil.show(name + ":安装成功");
|
ToastUtil.show(name + ":安装成功");
|
||||||
LogUtils.e(TAG, "安装了:" + packageName + "包名的程序");
|
LogUtils.e(TAG, "安装了:" + packageName + "包名的程序");
|
||||||
// ToastTool.show("安装成功");
|
// ToastTool.show("安装成功");
|
||||||
if (!packageName.equals(context.getPackageName())&&!packageName.equals("com.android.uiuios")) {
|
if (!packageName.equals(context.getPackageName()) && !packageName.equals("com.android.uiuios")) {
|
||||||
if (member_id == -1 || sn_id.equals("-1")) {
|
if (member_id == -1 || sn_id.equals("-1")) {
|
||||||
OKGOPost.getUserInfo(context);
|
OKGOPost.getUserInfo(context);
|
||||||
} else {
|
} else {
|
||||||
@@ -52,7 +53,7 @@ public class AppManagerReceiver extends BroadcastReceiver {
|
|||||||
LogUtils.e(TAG, "卸载了:" + packageName + "包名的程序");
|
LogUtils.e(TAG, "卸载了:" + packageName + "包名的程序");
|
||||||
Intent intents = new Intent("com.appstore.uiui.PACKAGE_REMOVED");
|
Intent intents = new Intent("com.appstore.uiui.PACKAGE_REMOVED");
|
||||||
context.sendBroadcast(intents);
|
context.sendBroadcast(intents);
|
||||||
if (!packageName.equals(context.getPackageName())&&!packageName.equals("com.android.uiuios")) {
|
if (!packageName.equals(context.getPackageName()) && !packageName.equals("com.android.uiuios")) {
|
||||||
if (member_id == -1 || sn_id.equals("-1")) {
|
if (member_id == -1 || sn_id.equals("-1")) {
|
||||||
OKGOPost.getUserInfo(context);
|
OKGOPost.getUserInfo(context);
|
||||||
} else {
|
} else {
|
||||||
@@ -60,6 +61,11 @@ public class AppManagerReceiver extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (action.equals(Intent.ACTION_USER_PRESENT)) {
|
||||||
|
LogUtils.e(TAG, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.9 KiB |
Reference in New Issue
Block a user