I am unable to see the following webpage in an Android webview: https://play.ericsson.net It should re-direct to a login page, can anyone produce a success case for opening the above webpage in an android webview?
FYI I'm activating javascript and setting WebViewClient.
Am I missing something?
Did you try this? Https sites are troublesome on android.
mWebView.setWebViewClient(new WebViewClient() {
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
}
Related
There are a lot of answer but none of them work . All of them work with this funciotn:
webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
webview.loadUrl("javascript:Test('Andrdoid-->Html')");
}
});
but it work one time after load page in webview . we want use it during app is open by user.
some says use this line
webview.loadUrl("javascript:Test('Andrdoid-->Html')");
without onPageFinished . but it cant help.
Javascript:
funtion Test(){
alert("hi");
}
webview.evaluateJavascript("Test('Andrdoid-->Html')", null);
loadUrl will reload the page and call onPageFinished() again.
You may try evulateJavascript.
evaluateJavascript, will run JavaScript asynchronously and avoid blocking the UI thread.
well, the best way to communicate with webview is to make a bridge between the native application and web app,
check this library it will help you to communicate with the web app.
Is it possible Redirect to specific url if page viewed from android by detecting it's package name (or another identificator information) from website (html or javascript)?
I think what you are looking is this meta tags.
I think this idea is impossible if you brows your web page from external browser (like google chrome).
So I suggest to brows the web page in a webview inside your android application and make your code listen for this webview by extend WebViewClient and call onPageFinished() :
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// do your stuff here
}
});
In the web app you can make a specific page for redirecting (for example www.your_website.com/redirecting.html) , and make the app do what you want when surf this link :
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// do your stuff here
if(url == "www.your_website.com/redirecting.html"){
//do what you want...
}
}
});
I need to send a notification (not necessarily a push notification) through an android webview. I saw that the Notification API was not compatible with Android Webview on MDN. The other APIs I saw seemed to be based off of window.notification.
Does anyone know of any API or JS that sends a notification through an android webview?
I saw this post from 6 months ago with essentially no activity except a vague mention of firebase. Would that be helpful?
Thanks for your answers!
I don't have enough "reputation" to post a comment but could that be useful to you?
Android Push Notification with WebView?
https://github.com/ashraf-alsamman/android-webview-app-with-push-notification
https://medium.com/shibinco/creating-a-webview-android-app-with-push-notification-7fd48541a913
Hopefuly you can make it work from one of those example
Read the documentation entry for Binding JavaScript code to Android code.
This allows you to use javascript to trigger the execution of android code.
First you have to register the Javascript Interface on android, so that you can trigger android code from javascript.
JAVA
WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
And define a method which does your action if the javascript is called. In this example show a toast.
public class WebAppInterface {
Context mContext;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
#JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
↑ You need to change that part to show your push notification instead. ↑
Then you can trigger the android code from javascript like this:
<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />
<script type="text/javascript">
function showAndroidToast(toast) {
Android.showToast(toast);
}
</script>
I did not tried it myself. But I would try to create a javascript method which makes an ajax request to a server in certain intervals and checks if there are new notifications to send and if true then call the android code to show the message.
However, you will have to make sure to only show the notification once somehow... maybe set a cookie containing the notification ID and set it to true, so that the android code is not getting triggered again.
You would need to provide the notifications for example as a .json file in JSON format. You can upload that .json file to your webserver somewhere. Then pass the content to android and parse it accordingly.
One Simple workaround use JSInterafce - communicate webview to native.tutorial
In that JSInterface pass, the desired parameter for notification and then use android system notification API to generate the notification.
I am developing a web app using sencha touch for all mobile devices. My application uses GPS feature. I would like to know how can I navigate to the native setting screen of the phone from my web app for the user to switch ON the GPS feature.
If the GPS is not ON, it will prompt user a popup which will take the user to location settings screen to turn ON the GPS.
Is this possible ?
Please let know. I have seen this feature in many apps, even in google maps.
It is not cording practice to do that. You can simply state the steps to be followed.
IF you are running webapp on Phonegap or Android web view, then you can do like this.
Read this article how to bind Javascript function to Native app.
http://developer.android.com/guide/webapps/webview.html#BindingJavaScript
Android Code
public class WebAppInterface {
/** Show a toast from the web page */
#JavascriptInterface
public void goToSettingPage() {
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
}
}
WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
JavaScript Code
<input type="button" value="Say hello" onClick="openSettingPage()" />
<script type="text/javascript">
function openSettingPage() {
Android.goToSettingPage();
}
</script>
I have a web page in which location is getting detected in web browser successfully. And based on location my results are filtered out. I am running same website url in a webview of android app. But in android app that location detection javascript is not working. Any suggestions what to do here?
Thanks in advance.
Doing the above still didn't work for me, but adding some additional code did - see Android Webview Geolocation
I added the following to my webview object
// enable geolocationEnabled
webview.getSettings().setGeolocationEnabled(true);
// enable JavaScriptCanOpenWindowsAutomatically, not sure if this is needed
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
// set setWebChromeClient
webview.setWebChromeClient(new WebChromeClient() {
public void onGeolocationPermissionsShowPrompt(String origin, android.webkit.GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
}
});
For some reason android.webkit.GeolocationPermissions.Callback had to be a fully qualify className, after adding it as an import it was still not recognized by the Eclipse IDE.
You should enable javascript for webview.
To do that,
wv = (WebView) findViewById(R.id.web_view);
wv.getSettings().setJavascriptEnabled(true);
Just one question: Does the location detection JS work in the Android Browser (not in the Android WebView)?
One thing to try is add the following to your manifest file:
<manifest ... >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
...
</manifest>
The second is to setJavaScriptEnabled(true) in your webview. I just noticed someone answered this below.
Read more here: http://developer.android.com/guide/topics/location/obtaining-user-location.html