|
|
@@ -1,8 +1,11 @@
|
|
|
package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.pm.PackageManager;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.view.View;
|
|
|
+import android.webkit.JavascriptInterface;
|
|
|
import android.webkit.WebChromeClient;
|
|
|
import android.webkit.WebSettings;
|
|
|
import android.webkit.WebView;
|
|
|
@@ -12,10 +15,18 @@ import android.widget.TextView;
|
|
|
import com.kfzs.android.view.widget.SafeWebView;
|
|
|
import com.kfzs.duanduan.BaseCompatActivity;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
+import com.zhy.http.okhttp.OkHttpUtils;
|
|
|
+import com.zhy.http.okhttp.callback.FileCallBack;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
import butterknife.ButterKnife;
|
|
|
+import okhttp3.Call;
|
|
|
|
|
|
import static com.kfzs.duanduan.bean.KFIntentKeys.EXTRA_WEBVIEW_NO_TITLE;
|
|
|
|
|
|
@@ -77,8 +88,8 @@ public class ActWeb extends BaseCompatActivity {
|
|
|
super.onReceivedTitle(view, title);
|
|
|
if(title == null)
|
|
|
TitleBarUtils
|
|
|
- .getInstance()
|
|
|
- .setTitle(ActWeb.this, title);
|
|
|
+ .getInstance()
|
|
|
+ .setTitle(ActWeb.this, title);
|
|
|
}
|
|
|
});
|
|
|
mWebView.setWebViewClient(new WebViewClient() {
|
|
|
@@ -97,15 +108,68 @@ public class ActWeb extends BaseCompatActivity {
|
|
|
}
|
|
|
});
|
|
|
webViewSettings.setJavaScriptEnabled(true);
|
|
|
- mWebView.loadUrl(url);
|
|
|
+ mWebView.addJavascriptInterface(new KFZSJs(), "kfzsjs");
|
|
|
+ mWebView.loadUrl(addUrl(url,"authorization", SpUtils.getOpenId(this)));
|
|
|
+ }
|
|
|
+ private String addUrl(String url, String key, String value){
|
|
|
+ return url + (url.contains("?") || url.contains("#") ? "&" : "?")+key+"="+value;
|
|
|
+ }
|
|
|
+ public class KFZSJs{
|
|
|
+ @JavascriptInterface
|
|
|
+ public void setTitle(String title){
|
|
|
+ TitleBarUtils
|
|
|
+ .getInstance()
|
|
|
+ .setTitle(ActWeb.this, title);
|
|
|
+ }
|
|
|
+ @JavascriptInterface
|
|
|
+ public void setCanGoBack(){
|
|
|
+ }
|
|
|
+ @JavascriptInterface
|
|
|
+ public void downloadFile(final String url, final String name){
|
|
|
+ OkHttpUtils.get()
|
|
|
+ .url(url)
|
|
|
+ .build()
|
|
|
+ .execute(new FileCallBack(ClassFileHelper.DIR, name) {
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+ G.showToast("下载文件失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(File response, int id) {
|
|
|
+ G.showToast("下载文件成功");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ @JavascriptInterface
|
|
|
+ public void startApp(String pkg, String cls){
|
|
|
+// try {
|
|
|
+// Intent intent = new Intent();
|
|
|
+// ComponentName cmp = new ComponentName(pkg,cls);
|
|
|
+// intent.setAction(Intent.ACTION_MAIN);
|
|
|
+// intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
|
+// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+// intent.setComponent(cmp);
|
|
|
+// startActivityForResult(intent, 0);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+ PackageManager packageManager = getPackageManager();
|
|
|
+ Intent launchIntentForPackage = packageManager.getLaunchIntentForPackage(pkg);
|
|
|
+ if (launchIntentForPackage != null)
|
|
|
+ startActivity(launchIntentForPackage);
|
|
|
+ else
|
|
|
+ G.showToast( "手机未安装该应用");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onBackPressed() {
|
|
|
+ public void finish() {
|
|
|
if(mWebView.canGoBack()){
|
|
|
mWebView.goBack();
|
|
|
return;
|
|
|
}
|
|
|
- this.finish();
|
|
|
+ super.finish();
|
|
|
}
|
|
|
}
|