I have a Flash file played in an Android application and interacting with it.
The Android version of this application is 2.3 .
The Flash file is embedded in an Android's WebView and interacting with the application through the: shouldInterceptRequest method of the: WebViewClient:
WebView web_Player;
web_Player.setWebViewClient(new WebViewClient() {
#Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
//CODE CODE CODE
}
}
The problem:
I need this code to support Android 2.2, which doesn't know the shouldInterceptRequest method.
How can I overcome this issue? In what other way can the Flash file communicate with the application in Android 2.2?
I've ended up using:
public void onLoadResource(WebView view, String url){}
Works perfectly.
Related
I am an hobbyist coder mostly limited to PHP and mysql. I developed a website for one client who also asked me to present it as an android app.
So I made an hybrid app following some youtube tutorials. It worked fine mostly
but In android version 7 and version 8, webview is deprecated. they are using chrome instead.
Now can anybody please suggest me some alternative way to show my website as an app in android.
also, can I migrate myapp from webview to chorome.
webView is not Deprecated.
The Following method in webView is deprecated
Android has deprecated shouldOverrideUrlLoading(WebView view, String url) {} in WebViewClient and replaced it with it with shouldOverrideUrlLoading(WebView, WebResourceRequest), presumably for greater long-term flexibility.
instead of using
boolean shouldOverrideUrlLoading (WebView view, String url)
use
shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
create a method called initWebView in onCreate
private void initWebView() {
webView.setWebChromeClient(new MyWebChromeClient(this));
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest request) {
webView.loadUrl(request.getUrl().toString());
return true;
}
}
this should do the job
I have an Android app that uses WebView to access my website (https://m.readster.com)
The issues is that my website uses a "location.reload(); " function in JavaScript when opening the app.
This works wonders on Android 26 and 27, but I have a Huawei with Android 22 that after the redirect, only shows a white page. If I remove the redirect script, it will display the page normally.
Is there any way to make it display the page after the Reload command?
EDIT
I was calling
public boolean shouldOverrideUrlLoading(WebView view, String url) {
I should have been calling
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
I've got a library included in my project, which exposes some assets in assets directory.
When running the app on Android 7, it works great and webview loads the assets fine. Today I have tested the app on Kitkat (API 19), and the resources loaded like file://android_asset/someAsset.png are not loaded.
I have checked the aar file created for my library and it contains those files [obviously, since the APK works fine on Android 7].
Here are my web settings:
WebSettings s = getSettings();
s.setAllowFileAccess(true);
s.setSupportZoom(false);
s.setBuiltInZoomControls(false);
s.setDomStorageEnabled(true);
s.setJavaScriptCanOpenWindowsAutomatically(true);
s.setUseWideViewPort(true);
s.setLoadWithOverviewMode(true);
s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
s.setJavaScriptEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
s.setMediaPlaybackRequiresUserGesture(false);
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
s.setAllowFileAccessFromFileURLs(true);
s.setAllowUniversalAccessFromFileURLs(true);
}
s.setGeolocationEnabled(false);
The error I get when debugging chrome is: File not found.
I have read some questions posted on SO, which refer to an IntelliJ setting: "Include assets from dependencies into APK" which is not there in Android Studio anymore. I have found however this doc page: https://developer.android.com/studio/projects/android-library.html which indicate, that adding
dependencies {
compile project(':myLib')
}
is enough to provide the assets to the main project [and it clearly does, hence the AAR contents].
Still, I cannot get those resources to show up.
I have also tried to copy the assets directory from the library to the main project, but still no luck. They are not loaded by webview and I get the same error.
I am going to answer my own question, because however stupid the problem is, who knows, maybe someone will stumble upon a similar issue.
I use shouldInterceptRequest method of WebViewClient to load files for WebView, as all of the content is encrypted and I have to decrypt it first.
Starting with Lollipop, the method has a different signature:
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request)
instead of
public WebResourceResponse shouldInterceptRequest(final WebView view, String url)
Since I have wrote my code using new devices, I simply had:
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
#Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { ... }
and it worked fine. When testing on old device, the method was not triggered at all and it would not find the file where it expected it.
After I have added support for this method, it all started to work.
Thanks #CommonsWare for the comment.
I have an App that uses custom schemes in Android WebViewClient's shouldInterceptRequest(WebView view, String url) and shouldOverrideUrlLoading(WebView view, String url) to intercept requests in a web application and use a native library to fetch resources from elsewhere in shouldInterceptRequest. This has worked fine up until Android 4.4 KitKat, where Google has made some crucial changes to the webView component.
http://developer.android.com/guide/webapps/migrating.html#URLs
Now the url received in shouldOverrideUrlLoading suddenly gets invalid, looking like this; custom-scheme:////my.pathname.com/. First I suspected the extra slashes were because Android did not think the url were valid RFC3986, but in a series of resource fetches (css, js, images), the url starts off correct and suddenly changes to the invalid format. The webView in Android 4.3 kept the url correctly as custom-scheme://my.pathname.com/. It seems like the base url suddenly changes to '/' instead of 'my.pathname.com'.
Then my attention changed to the fact that the webView 4.4 migration guide talks about:
If you call methods on WebView from any thread other than your app's UI thread, it can cause unexpected results. http://developer.android.com/guide/webapps/migrating.html#Threads
This also might be what I am experiencing, but I have not yet come up with a solution where I can use runOnUiThread() to fetch data with the native api and return it to the webView inside shouldInterceptRequest. Has anyone experienced something similar?
Here is a simplified version of my shouldInterceptRequest code:
#Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (urlStartsWithKnownPrefix(url)) {
UrlFetchResult fetchRes = api.fetchUrl(url);
String charset = "utf-8";
String mime = fetchRes.getMimetype();
WebResourceResponse res = new WebResourceResponse(mime, charset, new ByteArrayInputStream(fetchRes.getResult()));
return res;
}
return null;
}
Are you using jquery-mobile by any chance? This sounds very similar to: How can I use relative urls in ajax requests within trigger.io apps on Android 4.4 (kitkat)?
Does anyone knows an alternative to Android's webview component ? For some reasons, it's functionality's are insufficient for me : I need to be able to catch every single request to some url, when i'm browsing a wml page (wap). Anyway, I need to be able to do stuff that Android's webview is not made for.
I thought "hey, let's play with the source code, I'm pretty sure that webviews are using apache.org librairies to access internet".
Oh boy was I mistaken. Webviews use native code, and that's where I'm stuck.
So I was wondering if anyone knew of another web browser view, in pure java, that would be open source and nice. It's not a problem if it's slow, i'm displaying some basic wap pages...
Thanks in advance.
You can extend WebView's functionality by using setWebViewClient & setWebChromeClient.
WebView.setWebViewClient(new MyWebViewClient());
WebView.setWebChromeClient(new WebChromeClient() {..}
You can handle each and every request sent/received from the WebView by overriding the below methods:
public boolean shouldOverrideUrlLoading(WebView view, String url) {..}
public void onPageStarted(WebView view, String url, Bitmap favicon) {..}
public void onPageFinished(WebView view, String url) {..}
The crosswalk project: https://crosswalk-project.org/ might be what you need. But beware, there are places where it differs from the stock webview. In some ways better, in some ways worse. For example, it supports WebGL (good), but currently the background cannot be transparent (bad). The really good news, it seems to be very actively supported, running it's own Jira to track and fix and Intel seems to be very involved.
Try to see how was Opera Mini programmed.
But I think you must program it if you want another one . But i would be surprised if it has a nice performance.
Try this:
goButton4.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Uri uri = Uri.parse("http://tory.com/");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});