简体   繁体   English

知道用户是否从选择器中选择了意图动作的方法

[英]way to know if the user has chosen the intent action from chooser or not

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? 有任何想法吗?

You can do this by showing you own custom chooser 您可以通过显示自己的自定义选择器来完成此操作

First get all packages which can process your intent 首先获取可以处理您的意图的所有包

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

Then show a dialog with all this list of packages like this 然后显示一个对话框,工具包的所有这份名单是这样

Then process the click event and start the selected package 然后处理click事件并启动所选的包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在使用意图选择器时,如何知道用户选择了哪个应用程序? - How to know which application the user chose when using an intent chooser? 选择器意图没有应用 - Chooser intent has no apps Android如何根据选择器意图中的用户操作请求权限 - Android how to request permission based on user action in chooser intent 从 registerForActivityResult 中识别 Intent.ACTION_CHOOSER 中的选定选项 - Identify the selected option from Intent.ACTION_CHOOSER from the registerForActivityResult Android M - 有什么方法可以知道用户是否选择不再看到授予权限对话框? - Android M - Is there any way to know whether a user has chosen to never see the grant permissions dialog ever again? MIME类型和ACTION_SEND意向选择器 - MIME types and ACTION_SEND intent chooser 空意图选择器(没有应用程序可以执行此操作) - Empty intent chooser (No application can perform this action) 如何知道意图ACTION_TIME_CHANGED是否来自直接的用户交互 - How know if Intent ACTION_TIME_CHANGED is coming from direct user interaction 用户取消意图选择器时会发生事件吗? - Is there an event when user cancels intent chooser? 我如何知道用户在应用选择器中点击了哪个应用或按钮? - How can I know what app or button user has clicked in the app chooser?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM