Quellcode durchsuchen

修改webview支持下载链接

lijian vor 5 Jahren
Ursprung
Commit
687c80ee62

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

@@ -6,6 +6,7 @@ import android.content.Intent;
6 6
 import android.graphics.Bitmap;
7 7
 import android.graphics.Color;
8 8
 import android.graphics.drawable.GradientDrawable;
9
+import android.net.Uri;
9 10
 import android.os.Build;
10 11
 import android.os.Bundle;
11 12
 import android.util.Log;
@@ -13,6 +14,7 @@ import android.view.KeyEvent;
13 14
 import android.view.View;
14 15
 import android.webkit.CookieManager;
15 16
 import android.webkit.CookieSyncManager;
17
+import android.webkit.DownloadListener;
16 18
 import android.webkit.JavascriptInterface;
17 19
 import android.webkit.WebChromeClient;
18 20
 import android.webkit.WebResourceRequest;
@@ -134,18 +136,17 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
134 136
         //step3:(可选,强烈建议在合适的时机调用):申请部分权限,如read_phone_state,防止获取不了imei时候,下载类广告没有填充的问题。
135 137
         TTAdManagerHolder.get().requestPermissionIfNecessary(activity);
136 138
         this.mAQuery = new AQuery2(activity);
137
-
138 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 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 143
         } else {
143 144
             loadAd(ADConstants.AD_FULLSCREEN_VEDIEO, TTAdConstant.VERTICAL, false);
144 145
         }
145 146
         initWebView();
146 147
         if (mLoadUrl != null)
147 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 150
 //            mWebview.loadUrl("http://192.168.22.39/other/qianduo/games_h5/rotateCircle.html?id=8");
150 151
     }
151 152
 
@@ -266,6 +267,7 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
266 267
         mWebview.getSettings().setSupportZoom(false);
267 268
         mWebview.getSettings().setPluginState(WebSettings.PluginState.ON);
268 269
         mWebview.getSettings().setLoadWithOverviewMode(true);
270
+
269 271
 //        //图片不显示问题
270 272
         if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
271 273
 
@@ -276,6 +278,20 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
276 278
 ////        mWebview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
277 279
 ////        mWebview.getSettings().setSupportMultipleWindows(true);
278 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 295
         mWebview.setWebChromeClient(new WebChromeClient());
280 296
     }
281 297