我无法在“到网络视图”中打开特定的Google地图网址
这是我的代码
WebView wv = (WebView) view.findViewById(R.id.webPlace);
WebSettings ws = wv.getSettings();
ws.setPluginState(PluginState.ON);
ws.getSettings().setPluginState(WebSettings.PluginState.ON);
ws.setJavaScriptEnabled(true);
ws.setAllowFileAccess(true);
wv.loadUrl("https://www.google.com.sa/maps/place/Al+Com/@24.6930318,46.7746621,16z/data=!4m2!3m1!1s0x0000000000000000:0x154b423825155cce");
但每次我尝试运行此代码系统时强制我将此URL运行到android web浏览器的新活动中,但我需要在相同的应用程序活动中打开它,任何人都可以帮助我。
答案 0 :(得分:0)
请尝试此代码
class WebViewController extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
wv.setWebViewClient(new WebViewController());
wv.loadUrl("https://www.google.com.sa/maps/place/Al+Com/@24.6930318,46.7746621,16z/data=!4m2!3m1!1s0x0000000000000000:0x154b423825155cce");
答案 1 :(得分:0)
// oncreate
String url = "https://www.google.com.sa/maps/place/Al+Com/@24.6930318,46.7746621,16z/data=!4m2!3m1!1s0x0000000000000000:0x154b423825155cce";
new LoadSocialNetworkUrlTask().execute(url);
//的AsyncTask
public class LoadSocialNetworkUrlTask extends
AsyncTask<String, String, Void> {
protected void onPreExecute() {
dialog = new ProgressDialog(SocialNetworkActivity.this);
dialog.setMessage("Loading,Please wait...");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
dialog.show();
}
protected void onProgressUpdate(final String... url) {
try {
((WebView) webView).getSettings().setJavaScriptEnabled(true);
((WebView) webView).setBackgroundColor(Color.TRANSPARENT);
((WebView) webView).setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(WebView view,
SslErrorHandler handler, SslError error) {
handler.proceed(); // Ignore SSL certificate errors
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO hide your progress image
super.onPageFinished(view, url);
dialog.dismiss();
}
});
((WebView) webView).loadUrl(url[0]);
} catch (Exception e) {
e.printStackTrace();
dialog.dismiss();
}
}
@Override
protected Void doInBackground(String... url) {
try {
publishProgress(url);
} catch (Exception e) {
e.printStackTrace();
dialog.dismiss();
}
return null;
}
}