开发者

How to pass the parameters in custom intent chooser list?

开发者 https://www.devze.com 2023-03-16 06:59 出处:网络
I have created the custom intent chooser for maps(all installed maps in mobile). But now i am unable to pass lat/lon with it. My code is for getting all maps :

I have created the custom intent chooser for maps(all installed maps in mobile). But now i am unable to pass lat/lon with it. My code is for getting all maps :

final String mapUri = "geo:"+lat+ "," + lon + "?q="+ address;
Intent mapIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mapUri));

final PackageManager packageManager = getPackageManager();      
final List<ResolveInfo> mapList = packageManager.queryIntentActivities(mapIntent, 0);

For launching the map i am using this:

intentBuilder.setAdapter(adapter, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog,int item) 
            {
                Intent i = null;

                try 
                {
                    i = pm.getLaunchIntentForPackage(mapList.get(item).activityInfo.packageName);//.getIntent(uri);
                    startActivity(i);
                } 
                catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


                dialog.dismiss(开发者_C百科);
            }
       });
        AlertDialog alert = intentBuilder.create();
        alert.show();

This opens the map but without any location. How to pass the lat/lon or the URI to it?


At least one problem is here:

i = pm.getLaunchIntentForPackage(mapList.get(item).activityInfo.packageName);
startActivity(i);

What getLaunchIntentForPackage() does is build an ACTION_MAIN intent for the appropriate activity in the package name. So the Intent you are launching (a) Does not have your geo: URI in it, and (b) may not even be going to the same component you find in your original query.

When using queryIntentActivities() like this, to then go and launch one of the activities you found in the list the correct thing to do usually is to call Intent.setComponentName() on the original Intent to have that delivered to the specific component you want.

You build the ComponentName from the packageName and name of the ActivityInfo you want to launch.

0

精彩评论

暂无评论...
验证码 换一张
取 消