1

Is there a way to know if the user has chosen the intent action from the chooser or not.

I want to do this - If its chosen by user then finish the current activity else remain in the current activity.

I have this code:

startActivity(Intent.createChooser(email, "Choose an Email client :"));
finish();

But this always finishes the current activity irrespective of user chose the email client or not.

Any ideas?

4

1 回答 1

4

你可以通过展示你自己的自定义选择器来做到这一点

首先获取所有可以处理您的意图的包

private List<String> getInstalledComponentList(Intent emailIntent)
            throws NameNotFoundException {

        List<ResolveInfo> ril = getPackageManager().queryIntentActivities(emailIntent, 0);
        List<String> componentList = new ArrayList<String>();
        String name = null;

        for (ResolveInfo ri : ril) {
            if (ri.activityInfo != null) {
                Resources res = getPackageManager().getResourcesForApplication(ri.activityInfo.applicationInfo);
                if (ri.activityInfo.labelRes != 0) {
                    name = res.getString(ri.activityInfo.labelRes);
                } else {
                    name = ri.activityInfo.applicationInfo.loadLabel(
                            getPackageManager()).toString();
                }
                componentList.add(name);
            }
        }
        return componentList;
    } 

然后显示一个包含所有这些包列表的对话框,如下所示

然后处理点击事件并启动选中的包

于 2013-04-04T10:57:10.687 回答