[英]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.