version:1.0.4
fix: update:增加下载
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.xwad.os.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
@@ -10,15 +12,26 @@ import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.hjq.toast.Toaster;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.xwad.os.R;
|
||||
import com.xwad.os.bean.AppInfo;
|
||||
import com.xwad.os.bean.BaseResponse;
|
||||
import com.xwad.os.bean.LessonJson;
|
||||
import com.xwad.os.config.CommonConfig;
|
||||
import com.xwad.os.jxw.JxwPackageConfig;
|
||||
import com.xwad.os.manager.RemoteManager;
|
||||
import com.hjq.toast.Toaster;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.xwad.os.network.NetInterfaceManager;
|
||||
import com.xwad.os.service.DownloadService;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
@@ -27,6 +40,10 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
public class OpenApkUtils {
|
||||
private static final String TAG = "OpenApkUtils";
|
||||
|
||||
@@ -636,7 +653,7 @@ public class OpenApkUtils {
|
||||
*
|
||||
* @param paramStr 参数字符串(格式:包名,类名,extra参数,第四项,第五项)
|
||||
*/
|
||||
public void openJxwApp(String paramStr) {
|
||||
public void openJxwApp(Activity context, String paramStr) {
|
||||
if (TextUtils.isEmpty(paramStr)) {
|
||||
Log.e(TAG, "context为空或参数字符串为空");
|
||||
return;
|
||||
@@ -654,10 +671,15 @@ public class OpenApkUtils {
|
||||
String className = totalParts[1]; // 第二项:类名
|
||||
String extraParamStr = totalParts.length > 2 ? totalParts[2] : ""; // 第三项:Intent Extra参数
|
||||
String fourthParam = totalParts.length > 3 ? totalParts[3] : ""; // 第四项(自定义)
|
||||
String fifthParam = totalParts.length > 4 ? totalParts[4] : ""; // 第五项(自定义)
|
||||
String appName = totalParts.length > 4 ? totalParts[4] : ""; // 第五项(自定义)
|
||||
|
||||
Log.d(TAG, "包名:" + packageName + "\n类名:" + className
|
||||
+ "\n第四项:" + fourthParam + "\n第五项:" + fifthParam);
|
||||
+ "\n第四项:" + fourthParam + "\n应用名:" + appName);
|
||||
|
||||
if (!ApkUtils.isAvailable(mContext, packageName)) {
|
||||
showDownloadDialog(context, packageName, appName);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 构建Intent并设置Component(包名+类名)
|
||||
Intent intent = new Intent();
|
||||
@@ -689,7 +711,7 @@ public class OpenApkUtils {
|
||||
|
||||
// 4. 启动Activity(处理异常)
|
||||
try {
|
||||
mContext.startActivity(intent);
|
||||
context.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof android.content.ActivityNotFoundException) {
|
||||
Log.e(TAG, "未找到目标Activity:" + packageName + "/" + className);
|
||||
@@ -747,4 +769,77 @@ public class OpenApkUtils {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void showDownloadDialog(Activity context, String pkg, String appName) {
|
||||
Dialog dialog = new Dialog(context, R.style.ActionSheet);
|
||||
Window window = dialog.getWindow();
|
||||
View inflate = ((LayoutInflater) context.getSystemService("layout_inflater")).inflate(R.layout.download_dialog, (ViewGroup) null);
|
||||
TextView textView = inflate.findViewById(R.id.download_cancel);
|
||||
TextView textView2 = inflate.findViewById(R.id.tag_title);
|
||||
if (!TextUtils.isEmpty(appName)) {
|
||||
textView2.setText("未安装\"" + appName + "\"\n下载后可继续使用!");
|
||||
}
|
||||
TextView textView3 = inflate.findViewById(R.id.download_ok);
|
||||
textView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
textView3.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
getAppInfo(pkg);
|
||||
Intent intent = new Intent(mContext, DownloadService.class);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
mContext.startForegroundService(intent);
|
||||
} else {
|
||||
mContext.startService(intent);
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
WindowManager.LayoutParams attributes = window.getAttributes();
|
||||
attributes.x = 0;
|
||||
attributes.y = 0;
|
||||
attributes.gravity = 17;
|
||||
dialog.onWindowAttributesChanged(attributes);
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
dialog.setContentView(inflate);
|
||||
window.setDimAmount(0.6f);
|
||||
dialog.show();
|
||||
window.setAttributes(attributes);
|
||||
}
|
||||
|
||||
public void getAppInfo(String pkg) {
|
||||
NetInterfaceManager.getInstance().getAdminAppObservable(pkg)
|
||||
.subscribe(new Observer<BaseResponse<AppInfo>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getAppInfo", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<AppInfo> baseResponse) {
|
||||
Log.e("getAppInfo", "onNext: " + baseResponse);
|
||||
if (baseResponse.code == 200) {
|
||||
AppInfo appInfo = baseResponse.data;
|
||||
FileUtil.ariaDownload(mContext, appInfo.getApp_url(), appInfo);
|
||||
} else {
|
||||
Toaster.showLong("没有找到应用信息,请联系客服");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getAppInfo", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAppInfo", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user