Browse Source

修改webview支持下载链接

lijian 5 years ago
parent
commit
687c80ee62

+ 20 - 4
app/src/main/java/com/kuxuan/moneynote/ui/fragments/MoneyTaskFragmentActivity.java

6
 import android.graphics.Bitmap;
6
 import android.graphics.Bitmap;
7
 import android.graphics.Color;
7
 import android.graphics.Color;
8
 import android.graphics.drawable.GradientDrawable;
8
 import android.graphics.drawable.GradientDrawable;
9
+import android.net.Uri;
9
 import android.os.Build;
10
 import android.os.Build;
10
 import android.os.Bundle;
11
 import android.os.Bundle;
11
 import android.util.Log;
12
 import android.util.Log;
13
 import android.view.View;
14
 import android.view.View;
14
 import android.webkit.CookieManager;
15
 import android.webkit.CookieManager;
15
 import android.webkit.CookieSyncManager;
16
 import android.webkit.CookieSyncManager;
17
+import android.webkit.DownloadListener;
16
 import android.webkit.JavascriptInterface;
18
 import android.webkit.JavascriptInterface;
17
 import android.webkit.WebChromeClient;
19
 import android.webkit.WebChromeClient;
18
 import android.webkit.WebResourceRequest;
20
 import android.webkit.WebResourceRequest;
134
         //step3:(可选,强烈建议在合适的时机调用):申请部分权限,如read_phone_state,防止获取不了imei时候,下载类广告没有填充的问题。
136
         //step3:(可选,强烈建议在合适的时机调用):申请部分权限,如read_phone_state,防止获取不了imei时候,下载类广告没有填充的问题。
135
         TTAdManagerHolder.get().requestPermissionIfNecessary(activity);
137
         TTAdManagerHolder.get().requestPermissionIfNecessary(activity);
136
         this.mAQuery = new AQuery2(activity);
138
         this.mAQuery = new AQuery2(activity);
137
-
138
         if (isThirdGame) {
139
         if (isThirdGame) {
139
-            ViewCalculateUtil.setViewLinearLayoutParam(findViewById(R.id.fragment_moneytask_layout), LinearLayout.LayoutParams.MATCH_PARENT, 750, 0, 0, 0, 0, true);
140
+            ViewCalculateUtil.setViewLinearLayoutParam(findViewById(R.id.fragment_moneytask_layout), LinearLayout.LayoutParams.MATCH_PARENT, 800, 0, 0, 0, 0, true);
140
             ad_layout.setVisibility(View.GONE);
141
             ad_layout.setVisibility(View.GONE);
141
-            ViewCalculateUtil.setViewFrameLayoutParam(mWebview, FrameLayout.LayoutParams.MATCH_PARENT, 750, 0, 0, 0, 0, true);
142
+            ViewCalculateUtil.setViewFrameLayoutParam(mWebview, FrameLayout.LayoutParams.MATCH_PARENT, 800, 0, 0, 0, 0, true);
142
         } else {
143
         } else {
143
             loadAd(ADConstants.AD_FULLSCREEN_VEDIEO, TTAdConstant.VERTICAL, false);
144
             loadAd(ADConstants.AD_FULLSCREEN_VEDIEO, TTAdConstant.VERTICAL, false);
144
         }
145
         }
145
         initWebView();
146
         initWebView();
146
         if (mLoadUrl != null)
147
         if (mLoadUrl != null)
147
             mWebview.loadUrl(mLoadUrl);
148
             mWebview.loadUrl(mLoadUrl);
148
-//            mWebview.loadUrl("http://yun.banmaxingkong.cn/xhs/apk/xhs.apk");
149
+//            mWebview.loadUrl("http://182.92.118.1:8060/qianduo/games_h5/moveAgain.html?id=undefined");
149
 //            mWebview.loadUrl("http://192.168.22.39/other/qianduo/games_h5/rotateCircle.html?id=8");
150
 //            mWebview.loadUrl("http://192.168.22.39/other/qianduo/games_h5/rotateCircle.html?id=8");
150
     }
151
     }
151
 
152
 
266
         mWebview.getSettings().setSupportZoom(false);
267
         mWebview.getSettings().setSupportZoom(false);
267
         mWebview.getSettings().setPluginState(WebSettings.PluginState.ON);
268
         mWebview.getSettings().setPluginState(WebSettings.PluginState.ON);
268
         mWebview.getSettings().setLoadWithOverviewMode(true);
269
         mWebview.getSettings().setLoadWithOverviewMode(true);
270
+
269
 //        //图片不显示问题
271
 //        //图片不显示问题
270
         if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
272
         if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
271
 
273
 
276
 ////        mWebview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
278
 ////        mWebview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
277
 ////        mWebview.getSettings().setSupportMultipleWindows(true);
279
 ////        mWebview.getSettings().setSupportMultipleWindows(true);
278
         mWebview.setWebViewClient(mClient);
280
         mWebview.setWebViewClient(mClient);
281
+        mWebview.setDownloadListener(new DownloadListener() {
282
+            @Override
283
+            public void onDownloadStart(String s, String s1, String s2, String s3, long l) {
284
+//                Log.e("onDownloadStart",s+":"+s1+":"+s2+":"+s3);
285
+                try {
286
+                    Uri uri = Uri.parse(s);
287
+                    Intent intent = new Intent(Intent.ACTION_VIEW,uri);
288
+                    startActivity(intent);
289
+                }catch (Exception e){
290
+
291
+                }
292
+
293
+            }
294
+        });
279
         mWebview.setWebChromeClient(new WebChromeClient());
295
         mWebview.setWebChromeClient(new WebChromeClient());
280
     }
296
     }
281
 
297