Android intent for opening both Waze and Google maps

前端 未结 3 1306
一整个雨季
一整个雨季 2020-12-29 06:30

There are a few similar posts but I couldn\'t find an exact one. basically, I want to open both Google maps and Waze with the same intent. At first I tried this:

<         


        
相关标签:
3条回答
  • 2020-12-29 06:54

    Never mind. I was able to intercept the Facebook messenger with the below app and figured that the URI should be as follows:

    String.format(Locale.ENGLISH, "geo:0,0?q=") + android.net.Uri.encode(String.format("%s@%f,%f", label, latitude, longitude), "UTF-8");
    

    The app: https://play.google.com/store/apps/details?id=uk.co.ashtonbrsc.android.intentintercept&feature=search_result#?t=W251bGwsMSwyLDEsInVrLmNvLmFzaHRvbmJyc2MuYW5kcm9pZC5pbnRlbnRpbnRlcmNlcHQiXQ..

    Thanks

    0 讨论(0)
  • 2020-12-29 07:03

    My final solution for opening both Waze & GoogleMap applications to get direction ( works like a charm ) :

     String uri = "";
        Intent intent;
        try {
    
            uri = String.format(Locale.ENGLISH,"geo:" + location.getLat() + "," +location.getLng() + "?q=" + location.getLat()+","+location.getLng()+" ("+location.getName()+")");
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } catch (ActivityNotFoundException ex) {
            try {
                Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                startActivity(unrestrictedIntent);
            } catch (ActivityNotFoundException innerEx) {
                getSnackbar(getResources().getString(R.string.map_install_application), Snackbar.LENGTH_LONG).show();
            }
        }
    
    0 讨论(0)
  • 2020-12-29 07:09

    Following Nimrod's tip I've installed the app and intercepted the intent from whatsapp's location feature. Here's the full Intent tested on maps and waze:

    String uri = "http://maps.google.com/maps?q=loc:"+latitude+","+longitude+" ("+label+")";
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
    intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
    intent.setData(Uri.parse(uri));
    startActivity(intent);
    
    0 讨论(0)
提交回复
热议问题