update:2019.12.03

fix:
add:app强制弹窗更新
This commit is contained in:
2019-12-10 17:14:21 +08:00
parent 2653b91e70
commit ad7128d9ee
7 changed files with 100 additions and 16 deletions

View File

@@ -115,7 +115,7 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
//aria
//aria
implementation 'com.arialyy.aria:core:3.7.7'
annotationProcessor 'com.arialyy.aria:compiler:3.7.7'
//OKGO

View File

@@ -70,11 +70,12 @@
android:name=".receiver.AppManagerReceiver"
android:enabled="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_REPLACED" />
<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" />
</intent-filter>
</receiver>

View File

@@ -21,6 +21,7 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.appstore.uiui.BuildConfig;
import com.appstore.uiui.R;
import com.appstore.uiui.base.BaseActivity;
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.network.OKGOPost;
import com.appstore.uiui.service.MyDownloadService;
import com.appstore.uiui.utils.ApkUtils;
import com.appstore.uiui.utils.LogUtils;
import com.appstore.uiui.utils.SPUtils;
import com.appstore.uiui.utils.ToastUtil;
@@ -41,6 +43,10 @@ import com.flyco.tablayout.SlidingTabLayout;
import com.hjq.permissions.OnPermission;
import com.hjq.permissions.Permission;
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.util.ArrayList;
@@ -86,7 +92,7 @@ public class MainActivity extends BaseActivity {
// PackageManager pm = getPackageManager();
// pm.setApplicationEnabledSetting("com.tencent.qqmusic", PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
startService(new Intent(MainActivity.this, MyDownloadService.class));
CheckUpdate();
}
@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。如果已经初始化但没有登录成功则执行重新登录。
private void init() {
JPushInterface.init(getApplicationContext());
@@ -359,7 +369,35 @@ public class MainActivity extends BaseActivity {
case 2:
SPUtils.put(MainActivity.this, "isLogined", 2);
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);
}
});
}
}

View File

@@ -77,7 +77,7 @@ public class OKGOPost {
@Override
public void onError(Response<String> response) {
super.onError(response);
LogUtils.e("onError", response.getException().toString());
LogUtils.e("getAllAppInfo", response.getException().toString());
ToastUtil.show("网络连接失败,检查网络连接");
handler.sendEmptyMessage(0);
}
@@ -115,7 +115,7 @@ public class OKGOPost {
@Override
public void onError(Response<String> response) {
super.onError(response);
LogUtils.e("onError", response.getException().toString());
LogUtils.e("getRankApp", response.getException().toString());
ToastUtil.show("网络连接失败,检查网络连接");
handler.sendEmptyMessage(0);
}
@@ -155,7 +155,7 @@ public class OKGOPost {
@Override
public void onError(Response<String> response) {
super.onError(response);
LogUtils.e("onError", response.getException().toString());
LogUtils.e("searchAppbyName", response.getException().toString());
ToastUtil.show("网络连接失败,检查网络连接");
handler.sendEmptyMessage(0);
@@ -190,7 +190,7 @@ public class OKGOPost {
@Override
public void onError(Response<String> response) {
super.onError(response);
LogUtils.e("onError", response.getException().toString());
LogUtils.e("getUserInfo", response.getException().toString());
ToastUtil.show("网络连接失败,检查网络连接");
}
});
@@ -220,7 +220,7 @@ public class OKGOPost {
@Override
public void onError(Response<String> response) {
super.onError(response);
LogUtils.e("onError", response.getException().toString());
LogUtils.e("getUserInfo", response.getException().toString());
ToastUtil.show("网络连接失败,检查网络连接");
}
});
@@ -255,7 +255,7 @@ public class OKGOPost {
@Override
public void onError(Response<String> response) {
super.onError(response);
LogUtils.e("onError", response.getException().toString());
LogUtils.e("getSortApp", response.getException().toString());
ToastUtil.show("网络连接失败,检查网络连接");
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());
}
});
}
}

View File

@@ -17,5 +17,6 @@ public class Url {
//发送app安装信息
public final static String SET_APP_UNINSTALL_INFO = NETWORK_HOME_ADDRESS + "/App/appUnload";
//发送app卸载信息
public final static String GET_APP_UPDATE = NETWORK_HOME_ADDRESS + "/Update/update";
//根据包名获取更新
}

View File

@@ -14,21 +14,22 @@ import com.appstore.uiui.utils.ToastUtil;
public class AppManagerReceiver extends BroadcastReceiver {
private static final String TAG = "--AppManagerReceiver--";
private static final String TAG = "AppManagerReceiver";
private String action = null;
@Override
public void onReceive(Context context, Intent intent) {
int member_id = (int) SPUtils.get(context, "member_id", -1);
String sn_id = (String) SPUtils.get(context, "sn_id", "-1");
Log.e("BootReceiver", 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)){
if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {
Intent intents = new Intent("com.appstore.uiui.PACKAGE_ADDED");
context.sendBroadcast(intents);
}else {
} else {
Intent intents = new Intent("com.appstore.uiui.PACKAGE_REPLACED");
context.sendBroadcast(intents);
}
@@ -37,7 +38,7 @@ public class AppManagerReceiver extends BroadcastReceiver {
ToastUtil.show(name + ":安装成功");
LogUtils.e(TAG, "安装了:" + packageName + "包名的程序");
// 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")) {
OKGOPost.getUserInfo(context);
} else {
@@ -52,7 +53,7 @@ public class AppManagerReceiver extends BroadcastReceiver {
LogUtils.e(TAG, "卸载了:" + packageName + "包名的程序");
Intent intents = new Intent("com.appstore.uiui.PACKAGE_REMOVED");
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")) {
OKGOPost.getUserInfo(context);
} 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