'How to intent a map application if I go to google search google map intent google map?
i am new android devloper
They work well in my application. I have to open the map application if I click on Google Map. I only work with the map in the webview. I have to leave the webview if I click on the map. I tried many times but nothing worked for me.Below I have given some example.how slove this problem.......
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.net.http.SslError;
import android.os.Bundle;
import android.util.Log;
import android.webkit.ConsoleMessage;
import android.webkit.GeolocationPermissions;
import android.webkit.JavascriptInterface;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.core.app.ActivityCompat;
import static youngsterus.meo.app.Globals.TAG;
public class WebAppInterface implements NetworkMonitorCallbacks, AuthenticationCallbacks {
private final WebView webView;
private final String url;
private boolean webAppLoaded = false;
private boolean isOnline = false;
@SuppressLint("SetJavaScriptEnabled")
public WebAppInterface(final Activity context, final String url, Bundle previousState, AuthenticationProvider authenticationProvider) {
this.url = url;
context.setContentView(R.layout.activity_main);
webView = (WebView)context.findViewById(R.id.webview);
if (previousState != null) {
webView.restoreState(previousState);
} else {
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
Log.v(TAG, "Error on loading URL: " + failingUrl);
}
});
webView.setWebChromeClient(new WebChromeClient() {
public boolean onConsoleMessage(ConsoleMessage cm) {
Log.v(TAG, cm.message() + " -- From line "
+ cm.lineNumber() + " of "
+ cm.sourceId() );
return true;
}
});
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAppCachePath( context.getApplicationContext().getCacheDir().getAbsolutePath() );
webView.getSettings().setAllowFileAccess( true );
webView.getSettings().setAppCacheEnabled( true );
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(this, "Android");
webView.addJavascriptInterface(authenticationProvider, "AuthenticationProvider");
//// Geo location //////////
ActivityCompat.requestPermissions(context, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 123);
webView.setWebChromeClient(new WebChromeClient(){
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
// callback.invoke(String origin, boolean allow, boolean remember);
callback.invoke(origin, true, false);
}
});
}
}
public void load() {
Log.v(TAG, "Loading URL: " + url);
webView.loadUrl(url);
webAppLoaded = true;
}
@Override
public void networkStatusChange(boolean isOnline) {
this.isOnline = isOnline;
Log.v(TAG, "Network status changed to: " + isOnline );
if (isOnline) {
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
if(webAppLoaded) {
callJavaScript("goOnline");
} else {
load();
}
} else {
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
if(webAppLoaded) {
callJavaScript("goOffline");
} else {
load();
}
}
}
@JavascriptInterface
public void error(String error){
Log.v(TAG, "WebViewError: " + error);
}
@JavascriptInterface
public void log(String message) {
Log.v(TAG, "WebViewConsole: " + message);
}
@JavascriptInterface
public void getNetworkStatus() {
if (isOnline) {
callJavaScript("goOnline");
} else {
callJavaScript("goOffline");
}
}
public void callJavaScript(String methodName, Object...params){
boolean firstParam = true;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("javascript:try{");
stringBuilder.append(methodName);
stringBuilder.append("(");
for (Object param : params) {
if (!firstParam) {
stringBuilder.append(",");
firstParam = false;
}
if(param instanceof String){
stringBuilder.append("'");
stringBuilder.append(param);
stringBuilder.append("'");
}
}
stringBuilder.append(")}catch(error){Android.log(error);}");
Log.v(TAG, "Calling javascript: " + stringBuilder.toString());
webView.loadUrl(stringBuilder.toString());
}
public void saveState(Bundle bundle) {
webView.saveState(bundle);
}
@Override
public void onAuthenticationInfoReady(AuthenticationInfo authenticationInfo) {
callJavaScript("onAuthenticationInfoReady", authenticationInfo.toJSON());
}
@Override
public void onAccessTokenReady(String token) {
callJavaScript("onAccessTokenReady", token);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
