android – 空意图选择器(没有应用程序可以执行此 *** 作)

android – 空意图选择器(没有应用程序可以执行此 *** 作),第1张

概述我的intentchooser是基于白名单(只有一些选择将出现在意图选择器中).代码是基于另一个代码的代码;黑名单申请.我从 here和 this得到的代码是与之相关的相关讨论. 选择器如何创建的上下文: String[] whitelist = new String[] { "org.schiphol", "nl.negentwee", "org.schipholsecurity", "org. 我的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<Intent> targetedShareIntents = new ArrayList<Intent>();    List<HashMap<String,String>> intentMetaInfo = new ArrayList<HashMap<String,String>>();    Intent chooserIntent;    Intent dummy = new Intent(prototype.getAction());    dummy.setType(prototype.getType());    List<ResolveInfo> 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<String,String> info = new HashMap<String,String>();                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<HashMap<String,String>>() {            // @OverrIDe            // public int compare(HashMap<String,String> map,HashMap<String,String> map2) {            // return map.get("simplename").compareto(map2.get("simplename"));            // }            // });            MyLog.i(LOG_TAG,"--- creating custom intent List ---");            // create the custom intent List            for (HashMap<String,String> 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:35606-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 List06-28 13:04:48.687: I/NavigationTypeActivity(9400): adding org.schiphol to the intent List06-28 13:04:48.687: I/NavigationTypeActivity(9400): adding org.schipholsecurity to the intent List06-28 13:04:48.687: I/NavigationTypeActivity(9400): adding nl.negentwee to the intent List06-28 13:04:48.687: I/NavigationTypeActivity(9400): --- done compiling intent List ---06-28 13:04:48.687: I/NavigationTypeActivity(9400): total count targetedShareIntents: 406-28 13:04:48.687: I/NavigationTypeActivity(9400): --- chooser created ---06-28 13:04:48.687: E/NavigationTypeActivity(9400): returning filled (custom) chooser
解决方法 我从AndroID大师那里得到了一些反馈,告诉我应该用一个工作意图定义选择器,例如playstore或gmail等.从理论上讲,您可以提供OWN应用程序的启动意图(您确定已安装自己的应用程序).

Intent chooserIntent = Intent.createChooser(new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?ID=gmail")),"example");

之后,这就是列表从列表中删除单个项目的原因(您可能不希望在选择器中使用自己的应用程序).

总结

以上是内存溢出为你收集整理的android – 空意图选择器(没有应用程序可以执行此 *** 作)全部内容,希望文章能够帮你解决android – 空意图选择器(没有应用程序可以执行此 *** 作)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1124934.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存