Android intent for opening both Waze and Google maps

帅比萌擦擦* 提交于 2019-11-30 05:05:13

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

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);

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();
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!