【问题标题】:Google maps link is opening in webview谷歌地图链接正在 webview 中打开
【发布时间】:2013-09-30 09:11:32
【问题描述】:

我在 WebView 中制作了一个 android 应用程序。当我打开 Google 地图链接时,它会在 WebView 中打开,而不是在 Google 应用程序中。我怎样才能解决这个问题?我在 Google 和 Stack Overflow 上搜索过,但找不到任何解决方案。

代码:

public class FullscreenActivity extends Activity {

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fullscreen);

    webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new myWebClient());
    webView.loadUrl("http://www.mywebsite.nl");
    webView.setVerticalScrollBarEnabled(false);
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
}

public class myWebClient extends WebViewClient
{
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
    // TODO Auto-generated method stub
    super.onPageStarted(view, url, favicon);
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

if (url.startsWith("tel:")) { 
         Intent intent = new Intent(Intent.ACTION_DIAL,
                 Uri.parse(url)); 
         startActivity(intent); 
 }else if(url.startsWith("http:") || url.startsWith("https:")) {
     view.loadUrl(url);
 }
 return true;

    }
}

【问题讨论】:

  • When I open a Google maps link, it's opening in WebView and not in the Google app. 这是什么意思?您仅在 WebView 中打开链接,因此它显然只会打开链接 WebView
  • 来吧,您的代码中添加了一个 WebView...如果您想打开地图,请改用 MapFragment(不在 Google 应用程序中的 Webview 中)

标签: android google-maps webview


【解决方案1】:
Use following Map Fragment in Your layout xml file
 <fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="50dp"
    android:layout_marginTop="50dp"
    class="com.google.android.gms.maps.SupportMapFragment" />

有关详细信息,请参阅以下答案

[http://stackoverflow.com/questions/16395495/add-google-map-to-android-app][1]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-23
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 2019-12-18
    • 1970-01-01
    相关资源
    最近更新 更多