mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 20:33:07 +08:00
Attempt to test icecream_workaround from viafirma
This commit is contained in:
commit
adc88f01b7
@ -21,20 +21,26 @@ package org.apache.cordova;
|
|||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
import org.apache.cordova.api.CordovaInterface;
|
import org.apache.cordova.api.CordovaInterface;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.apache.cordova.api.LOG;
|
import org.apache.cordova.api.LOG;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.content.res.AssetManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.http.SslError;
|
import android.net.http.SslError;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.webkit.HttpAuthHandler;
|
import android.webkit.HttpAuthHandler;
|
||||||
import android.webkit.SslErrorHandler;
|
import android.webkit.SslErrorHandler;
|
||||||
|
import android.webkit.WebResourceResponse;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
|
|
||||||
@ -241,6 +247,7 @@ public class CordovaWebViewClient extends WebViewClient {
|
|||||||
* Notify the host application that a page has finished loading.
|
* Notify the host application that a page has finished loading.
|
||||||
* This method is called only for main frame. When onPageFinished() is called, the rendering picture may not be updated yet.
|
* This method is called only for main frame. When onPageFinished() is called, the rendering picture may not be updated yet.
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* @param view The webview initiating the callback.
|
* @param view The webview initiating the callback.
|
||||||
* @param url The url of the page.
|
* @param url The url of the page.
|
||||||
*/
|
*/
|
||||||
@ -344,6 +351,7 @@ public class CordovaWebViewClient extends WebViewClient {
|
|||||||
|
|
||||||
final String packageName = this.cordova.getActivity().getPackageName();
|
final String packageName = this.cordova.getActivity().getPackageName();
|
||||||
final PackageManager pm = this.cordova.getActivity().getPackageManager();
|
final PackageManager pm = this.cordova.getActivity().getPackageManager();
|
||||||
|
|
||||||
ApplicationInfo appInfo;
|
ApplicationInfo appInfo;
|
||||||
try {
|
try {
|
||||||
appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
|
appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
|
||||||
@ -451,4 +459,39 @@ public class CordovaWebViewClient extends WebViewClient {
|
|||||||
this.authenticationTokens.clear();
|
this.authenticationTokens.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
|
||||||
|
if(url.contains("?")){
|
||||||
|
return generateWebResourceResponse(url);
|
||||||
|
} else {
|
||||||
|
return super.shouldInterceptRequest(view, url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private WebResourceResponse generateWebResourceResponse(String url) {
|
||||||
|
final String ANDROID_ASSET = "file:///android_asset/";
|
||||||
|
if (url.startsWith(ANDROID_ASSET)) {
|
||||||
|
String niceUrl = url;
|
||||||
|
niceUrl = url.replaceFirst(ANDROID_ASSET, "");
|
||||||
|
if(niceUrl.contains("?")){
|
||||||
|
niceUrl = niceUrl.split("\\?")[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
String mimetype = null;
|
||||||
|
if(niceUrl.endsWith(".html")){
|
||||||
|
mimetype = "text/html";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
AssetManager assets = cordova.getActivity().getAssets();
|
||||||
|
Uri uri = Uri.parse(niceUrl);
|
||||||
|
InputStream stream = assets.open(uri.getPath(), AssetManager.ACCESS_STREAMING);
|
||||||
|
WebResourceResponse response = new WebResourceResponse(mimetype, "UTF-8", stream);
|
||||||
|
return response;
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.e("generateWebResourceResponse", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user