我有一个关于意图的问题......我尝试启动短信应用...
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setType("vnd.android-dir/mms-sms");
int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_CLEAR_TOP;
intent.setFlags(flags);
intent.setData(Uri.parse("content://sms/inbox"));
context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
所以,你可以看到我在我的意图中放了太多东西,但那是因为我不知道我该怎么办...谢谢
我试图得到给定的默认/首选应用程序Intent.例如,当用户安装第二个Web浏览器,然后尝试打开URL时,他或她将获得如下对话框:

如果用户随后选择" 默认使用此操作"选项,则在按下URL时将不再打开该对话框.
我正在开发一个应该知道这个默认或首选 app/action的应用程序.我该怎么做呢?我目前正在使用下面的代码,但getPreferredPackage不会返回任何内容:
Intent i = (new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com"));
PackageManager pm = context.getPackageManager();
final List<ResolveInfo> list = pm.queryIntentActivities(i, 0);
IntentFilter ifilter = new IntentFilter(i.getAction());
if (i.getCategories() != null) {
for(String category : i.getCategories()) {
ifilter.addCategory(category);
}
}
List<IntentFilter> filters = new ArrayList<IntentFilter>();
filters.add(ifilter);
List<ComponentName> preferredActivities = new ArrayList<ComponentName>();
pm.getPreferredActivities(filters, preferredActivities, null);
for (ComponentName activity : preferredActivities) {
for (ResolveInfo rinfo : list) {
if (rinfo.activityInfo.applicationInfo.packageName.equals(activity.getPackageName())) {
try {
final PackageInfo …Run Code Online (Sandbox Code Playgroud)