意图:删除始终/仅一次按钮

问题描述 投票:6回答:3

我是Android开发的新手。

打开Intent.ACTION_GET_CONTENT时是否可以删除两个按钮(始终/仅一次)?

这是我目前的代码。

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent,PICK);
android android-intent
3个回答
13
投票

我找到了实现这个目标的方法:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
Intent openInChooser = Intent.createChooser(intent, "Open in...");
startActivityForResult(openInChooser,PICK);

0
投票

这是一个系统生成的对话框,因此您无法对其进行更改。

您可以使用queryIntentActivities()获取可以响应您的意图的应用程序列表,然后根据您的喜好在没有按钮的情况下在您自己的对话框中显示它们。


0
投票

关键是要创建一个Intent.createChooser(),如果你调用Intent.createChooser(),将它传递给你的Intent对象,它会返回你的意图版本,它将始终显示选择器。例:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my awesome text to share.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Share via"));
© www.soinside.com 2019 - 2024. All rights reserved.