Android 默认浏览器下载apk,点击无法安装

1.1 默认浏览器下载apk显示成bin文件
  • 源码路径: /vendor/mediatek/proprietary/packages/apps/Browser/src/com/android/browser/util/MimeTypeMap.java
 public static String getFileExtensionFromUrl(String url) {
    
    
 	if (!TextUtils.isEmpty(url)) {
    
    
    	int fragment = url.lastIndexOf('#');
    	if (fragment > 0) {
    
    
    		url = url.substring(0, fragment);
    	}
    	
    	int query = url.lastIndexOf('?');
    	if (query > 0) {
    
    
    		url = url.substring(0, query);
    	}
    	
    	int filenamePos = url.lastIndexOf('/');
    	String filename = 
    		0 <= filenamePos ? url.substring(filenamePos + 1) : url;
    		
    	// if the filename contains special characters, we don't
    	// consider it valid for our matching purposes:
    	if (!filename.isEmpty() &&
  +  		// add start 
  +  		//Pattern.matches("[a-zA-Z_0-9\\.\\-\\(\\)\\%]+", filename)) {
    
    
  +  		Pattern.matches("[\u4e00-\u9fa5_a-zA-Z_0-9\\.\\-\\(\\)\\%]+", filename)) {
    
    
  +  		// add end
    		int dotPos = filename.lastIndexOf('.');
    		if (0 <= dotPos) {
    
    
    			return filename.substring(dotPos + 1);
    		}
    	}
    }
    return "";
 }
1.2 默认浏览器部分视频下载失败
  • 源码路径:vendor/mediatek/proprietary/packages/apps/Browser/src/com/android/browser/DownloadHandler.java
 public static void onDownloadStartNoStream(Activity activity,
            String url, String userAgent, String contentDisposition,
            String mimetype, String referer, boolean privateBrowsing, long contentLength) {
    
    
            ...
     // let this downloaded file be scanned by MediaScanner - so that it can
     // show up in Gallery app, for example.
     request.allowScanningByMediaScanner();
     request.setDescription(webAddress.getHost());
     // XXX: Have to use the old url since the cookies were stored using the
     // old percent-encoded url.
     String cookies = CookieManager.getInstance().getCookie(url, privateBrowsing);
  +   // add start
  +   if (referer == null || referer.isEmpty()) referer = "https://www.baidu.com";
  +   // add end
     request.addRequestHeader("cookie", cookies);
     request.addRequestHeader("User-Agent", userAgent);
     request.addRequestHeader("Referer", referer);
     request.setNotificationVisibility(
             DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
     //request.setUserAgent(userAgent);
     ...
 }
1.3 默认浏览器下载的apk,不能安装问题
  • 源码路径:/vendor/mediatek/proprietary/packages/apps/Browser/src/com/android/browser/util/URLUtil.java
 public static final String guessFileName(
            String url,
            String contentDisposition,
            String mimeType) {
    
    
            ...
      	// Finally, if couldn't get filename from URI, get a generic filename
     	if (filename == null) {
    
    
         	filename = "downloadfile";
     	}
     	
  +		// add start
  +   	if (filename.endsWith(".apk")
  +			&& mimeType != null
  +			&& mimeType.equals("application/octet-stream")
  +			||mimeType.equals("binary/octet-stream")) {
    
    
  +         mimeType = "application/vnd.android.package-archive";
  +  	}
  +		// add end
  			...
 }           
1.4 浏览器导航页面多个标签网页不能打开问题
  • 源码路径:vendor/mediatek/proprietary/packages/apps/Browser/res/values/mtk_strings.xml
   <string-array name="predefined_websites_default_optr" translatable="false">
         <item>START NEWS</item>
-        <item>https://locale.searchhtt.com/bm/index/54</item>
+        <item>https://www.start.com/</item>
         <item>site_navigation_default_startnews</item>
 
         <item>Ctrip</item>
-        <item>https://locale.searchhtt.com/bm/index/43</item>
+        <item>https://www.ctrip.com/</item>
         <item>site_navigation_default_ctrip</item>
 
         <item>Facebook</item>
-        <item>https://locale.searchhtt.com/bm/index/26</item>
+        <item>https://www.facebook.com/</item>
         <item>site_navigation_default_facebook</item>              
  • 源码路径:vendor/mediatek/proprietary/packages/apps/Browser/res/values/strings.xml
 <string-array name="bookmarks" translatable="false">
         <item>START NEWS</item>
-        <item>https://locale.searchhtt.com/bm/index/54</item>
+        <item>https://www.start.com/</item>
         <item>Google</item>
-        <item>https://locale.searchhtt.com/bm/index/25</item>
+        <item>https://www.google.com/</item>
         <item>Facebook</item>
-        <item>https://locale.searchhtt.com/bm/index/26</item>
+        <item>https://www.facebook.com/</item>
         <item>Aliexpress</item>

猜你喜欢

转载自blog.csdn.net/wxd_csdn_2016/article/details/129177181
今日推荐