|
|
@@ -4,6 +4,8 @@ import android.app.Activity;
|
|
|
import android.text.TextUtils;
|
|
|
import android.webkit.JavascriptInterface;
|
|
|
|
|
|
+import com.tencent.smtt.sdk.WebView;
|
|
|
+
|
|
|
import com.kfzs.duanduan.utils.ApkUtils;
|
|
|
import com.sheep.gamegroup.util.share.ShareLinkConfig;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
@@ -27,16 +29,19 @@ import okhttp3.Call;
|
|
|
public class WebViewJs {
|
|
|
|
|
|
private WeakReference<Activity> actRef;
|
|
|
+ private WeakReference<WebView> webRef;
|
|
|
|
|
|
private int taskId;
|
|
|
|
|
|
- public WebViewJs(Activity activity) {
|
|
|
+ public WebViewJs(Activity activity, WebView webView) {
|
|
|
actRef = new WeakReference<>(activity);
|
|
|
+ webRef = new WeakReference<>(webView);
|
|
|
}
|
|
|
|
|
|
- public WebViewJs(Activity activity, int taskId) {
|
|
|
+ public WebViewJs(Activity activity, WebView webView, int taskId) {
|
|
|
this.taskId = taskId;
|
|
|
actRef = new WeakReference<>(activity);
|
|
|
+ webRef = new WeakReference<>(webView);
|
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
|
@@ -135,15 +140,16 @@ public class WebViewJs {
|
|
|
* @return
|
|
|
*/
|
|
|
@JavascriptInterface
|
|
|
- public int CheckInstall(String packName) {
|
|
|
+ public void CheckInstall(String packName) {
|
|
|
if (TextUtils.isEmpty(packName)) {
|
|
|
G.showToast("包名为空");
|
|
|
- return 0;
|
|
|
}
|
|
|
- if (actRef.get() != null) {
|
|
|
- return PackageUtil.isAppInstalled(actRef.get(), packName) ? 1 : 0;
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
+ if (webRef.get() != null) {
|
|
|
+ webRef.get().post(() -> {
|
|
|
+ if (webRef == null) return;
|
|
|
+ int ret = PackageUtil.isAppInstalled(actRef.get(), packName) ? 1 : 0;
|
|
|
+ webRef.get().loadUrl("javascript:CheckInstall_Return(" + ret + ")");
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -164,6 +170,7 @@ public class WebViewJs {
|
|
|
G.showToast("下载地址为空");
|
|
|
return 0;
|
|
|
}
|
|
|
+ G.showToast("开始下载");
|
|
|
downLoad(packName);
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -174,7 +181,7 @@ public class WebViewJs {
|
|
|
G.showToast("连接地址为空");
|
|
|
return 0;
|
|
|
}
|
|
|
- if(actRef.get()!=null) {
|
|
|
+ if (actRef.get() != null) {
|
|
|
Jump2View.getInstance().goWeb(actRef.get(), url);
|
|
|
}
|
|
|
return 0;
|
|
|
@@ -192,7 +199,7 @@ public class WebViewJs {
|
|
|
|
|
|
@Override
|
|
|
public void onResponse(File response, int id) {
|
|
|
- if (response.getAbsolutePath().endsWith(".apk") && actRef.get()!=null) {
|
|
|
+ if (response.getAbsolutePath().endsWith(".apk") && actRef.get() != null) {
|
|
|
ApkUtils.installApk(actRef.get(), response.getAbsolutePath());
|
|
|
}
|
|
|
}
|