
如果用户然后选择该 *** 作选项的“默认使用”选项,则当按下URL时,该对话框将不再打开.
我正在处理一个应该知道这个默认或首选应用/ *** 作的应用程序.我该怎么做?我目前正在使用下面的代码,但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 pi = pm.getPackageInfo(activity.getPackagename(),0); Toast.makeText(context,pm.getApplicationLabel(pi.applicationInfo),Toast.LENGTH_SHORT).show(); } } catch (nameNotFoundException e) { e.@R_404_1715@(); } }} 我究竟做错了什么?这甚至是正确的做法吗?
解决方法 那么这个解决方案比我做的简单得多(尽管这很简单).以下代码是我的解决方案:Intent i = (new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.Google.com"));PackageManager pm = context.getPackageManager();final ResolveInfo mInfo = pm.resolveActivity(i,0);Toast.makeText(context,pm.getApplicationLabel(mInfo.activityInfo.applicationInfo),Toast.LENGTH_LONG).show(); 总结 以上是内存溢出为你收集整理的在Android上获取首选/默认应用全部内容,希望文章能够帮你解决在Android上获取首选/默认应用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)