Android显示意图代码,android – 空意图选择器(没有应用程序可以执行此操作)

我的intentchooser是基于白名单(只有一些选择将出现在意图选择器中).代码是基于另一个代码的代码;黑名单申请.我从

here和

this得到的代码是与之相关的相关讨论.

选择器如何创建的上下文:

String[] whitelist = new String[] { "org.schiphol", "nl.negentwee", "org.schipholsecurity", "org.chineseschiphol", "nl.ns", "com.tomtom" };

Intent intent = new Intent(Intent.ACTION_MAIN);

//intent.addCategory(Intent.CATEGORY_LAUNCHER);

startActivity(generateCustomChooserIntent(intent, whitelist));

我用来创建列入白名单的选择器的方法;

// Method:

private Intent generateCustomChooserIntent(Intent prototype, String[] whiteList) {

List targetedShareIntents = new ArrayList();

List> intentMetaInfo = new ArrayList>();

Intent chooserIntent;

Intent dummy = new Intent(prototype.getAction());

dummy.setType(prototype.getType());

List resInfo = getPackageManager().queryIntentActivities(dummy, 0);

MyLog.i(LOG_TAG, "Apps installed on device:" + resInfo.size());

if (!resInfo.isEmpty()) {

for (ResolveInfo resolveInfo : resInfo) {

// MyLog.i(LOG_TAG, "Looking at:" + resolveInfo.activityInfo.packageName);

if (resolveInfo.activityInfo == null) {

MyLog.e(LOG_TAG, "resolved application has no activity info, so it is not usable.");

continue;

}

if (Arrays.asList(whiteList).contains(resolveInfo.activityInfo.packageName)) {

// MyLog.i(LOG_TAG, "=============================> accepted");

HashMap info = new HashMap();

info.put("packageName", resolveInfo.activityInfo.packageName);

info.put("className", resolveInfo.activityInfo.name);

info.put("simpleName", String.valueOf(resolveInfo.activityInfo.loadLabel(getPackageManager())));

intentMetaInfo.add(info);

} else {

// MyLog.i(LOG_TAG, "rejected");

}

}

if (!intentMetaInfo.isEmpty()) {

MyLog.i(LOG_TAG, "--- done compiling list ---");

// TODO enable sorting again

// sorting for nice readability

// Collections.sort(intentMetaInfo, new Comparator>() {

// @Override

// public int compare(HashMap map, HashMap map2) {

// return map.get("simpleName").compareTo(map2.get("simpleName"));

// }

// });

MyLog.i(LOG_TAG, "--- creating custom intent list ---");

// create the custom intent list

for (HashMap metaInfo : intentMetaInfo) {

MyLog.i(LOG_TAG, "adding " + metaInfo.get("packageName") + " to the intent list");

Intent targetedShareIntent = (Intent) prototype.clone();

targetedShareIntent.setPackage(metaInfo.get("packageName"));

targetedShareIntent.setClassName(metaInfo.get("packageName"), metaInfo.get("className"));

targetedShareIntents.add(targetedShareIntent);

}

MyLog.i(LOG_TAG, "--- done compiling intent list ---");

MyLog.i(LOG_TAG, "total count targetedShareIntents: " + targetedShareIntents.size());

chooserIntent = Intent.createChooser(targetedShareIntents.remove(targetedShareIntents.size() - 1), "Selecteer reis app (1)");

MyLog.i(LOG_TAG, "--- chooser created ---");

chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {}));

MyLog.e(LOG_TAG, "returning filled (custom) chooser");

return chooserIntent;

}

}

MyLog.e(LOG_TAG, "returning default chooser (empty)");

return Intent.createChooser(prototype, "Selecteer reis app");

}

现在发生的事情是结果选择器显示“没有应用程序可以执行此操作”虽然logcat显示已选择5个应用程序.

Logcat记录结果:

06-28 13:04:48.679: I/NavigationTypeActivity(9400): Apps installed on device:356

06-28 13:04:48.687: I/NavigationTypeActivity(9400): --- done compiling list ---

06-28 13:04:48.687: I/NavigationTypeActivity(9400): --- creating custom intent list ---

06-28 13:04:48.687: I/NavigationTypeActivity(9400): adding org.chineseschiphol to the intent list

06-28 13:04:48.687: I/NavigationTypeActivity(9400): adding org.schiphol to the intent list

06-28 13:04:48.687: I/NavigationTypeActivity(9400): adding org.schipholsecurity to the intent list

06-28 13:04:48.687: I/NavigationTypeActivity(9400): adding nl.negentwee to the intent list

06-28 13:04:48.687: I/NavigationTypeActivity(9400): --- done compiling intent list ---

06-28 13:04:48.687: I/NavigationTypeActivity(9400): total count targetedShareIntents: 4

06-28 13:04:48.687: I/NavigationTypeActivity(9400): --- chooser created ---

06-28 13:04:48.687: E/NavigationTypeActivity(9400): returning filled (custom) chooser

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值