diff --git a/app/build.gradle b/app/build.gradle index 6f05253..1dc7ce3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d213d62..abfc286 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -70,11 +70,12 @@ android:name=".receiver.AppManagerReceiver" android:enabled="true" android:exported="true"> - + - + + diff --git a/app/src/main/java/com/appstore/uiui/activity/MainActivity.java b/app/src/main/java/com/appstore/uiui/activity/MainActivity.java index f5ba387..7f88310 100644 --- a/app/src/main/java/com/appstore/uiui/activity/MainActivity.java +++ b/app/src/main/java/com/appstore/uiui/activity/MainActivity.java @@ -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.get(url) + .execute(new FileCallback() { + @Override + public void onSuccess(Response 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 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); + } + }); + } } diff --git a/app/src/main/java/com/appstore/uiui/network/OKGOPost.java b/app/src/main/java/com/appstore/uiui/network/OKGOPost.java index 28f3317..4faa90b 100644 --- a/app/src/main/java/com/appstore/uiui/network/OKGOPost.java +++ b/app/src/main/java/com/appstore/uiui/network/OKGOPost.java @@ -77,7 +77,7 @@ public class OKGOPost { @Override public void onError(Response 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 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 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 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 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 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.post(Url.GET_APP_UPDATE) + .params("code", versionCode) + .params("package", packageName) + .execute(new StringCallback() { + @Override + public void onSuccess(Response 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 response) { + super.onError(response); + Log.e("checkUpdateByPackage", response.getException().toString()); + } + }); + } + } diff --git a/app/src/main/java/com/appstore/uiui/network/URLs/Url.java b/app/src/main/java/com/appstore/uiui/network/URLs/Url.java index a9adfd2..3657c35 100644 --- a/app/src/main/java/com/appstore/uiui/network/URLs/Url.java +++ b/app/src/main/java/com/appstore/uiui/network/URLs/Url.java @@ -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"; + //根据包名获取更新 } diff --git a/app/src/main/java/com/appstore/uiui/receiver/AppManagerReceiver.java b/app/src/main/java/com/appstore/uiui/receiver/AppManagerReceiver.java index 26d6aa6..808653b 100644 --- a/app/src/main/java/com/appstore/uiui/receiver/AppManagerReceiver.java +++ b/app/src/main/java/com/appstore/uiui/receiver/AppManagerReceiver.java @@ -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); + } + + } diff --git a/app/src/main/res/drawable/icon_serach.png b/app/src/main/res/drawable/icon_serach.png index 5528b27..284852f 100644 Binary files a/app/src/main/res/drawable/icon_serach.png and b/app/src/main/res/drawable/icon_serach.png differ