0

I have made an android app in WebView. When I open a Google maps link, it's opening in WebView and not in the Google app. How can I fix this? I have searched on Google and on Stack Overflow but can't find the any solution.

Code:

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;

    }
}
Marv
  • 33
  • 11
  • `When I open a Google maps link, it's opening in WebView and not in the Google app.` What do you mean by this ? You are opening link in `WebView` only so it will obviously open link `WebView` only. – GrIsHu Sep 30 '13 at 09:50
  • come on there is a WebView added in your code...use MapFragment instead if you want to open a map (not in Webview nd in Google app) – mananjani Sep 30 '13 at 11:44

1 Answers1

0
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" />

and refer following answer for more details

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