如何检测,可以处理请求的意图行动Android应用?

编程入门 行业动态 更新时间:2024-10-26 18:24:19
本文介绍了如何检测,可以处理请求的意图行动Android应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想分享短信低谷的Twitter,Facebook或者以其他方式在设备可用。我写了接下来code:

意图份额=新意图(Intent.ACTION_SEND);    share.putExtra(Intent.EXTRA_TEXT,这是Twitter的一些文字。);    startActivity(Intent.createChooser(份额,通过共享此));

但是,如果没有应用程序,可以hadle这个动作,出现在屏幕上的没有这样的应用程序对话框。我要检测这些应用程序和关闭此功能,如果没有找到处理程序。我该怎么办呢?

解决方案

意向意图=新意图...    软件包管理系统经理= mContext.getPackageManager();    清单< ResolveInfo>清单= manager.queryIntentActivities(意向,0);    如果(名单= NULL&放大器;!&安培;则为list.size()0){        //你至少有一个活动来处理这个意图    }其他{        //没有活动处理的意图。    }

I want to share text message trough twitter, facebook or in other ways that available on device. I wrote next code:

Intent share = new Intent(Intent.ACTION_SEND); share.putExtra(Intent.EXTRA_TEXT, "Here's some text for Twitter."); startActivity(Intent.createChooser(share, "Share this via"));

But if no apps that can hadle this action, the "no such apps" dialog appears on screen. I want to detect these apps and disable this function if there is no handlers found. How I can do it?

解决方案

Intent intent = new Intent... PackageManager manager = mContext.getPackageManager(); List<ResolveInfo> list = manager.queryIntentActivities(intent, 0); if (list != null && list.size() > 0) { //You have at least one activity to handle the intent } else { //No activity to handle the intent. }

更多推荐

如何检测,可以处理请求的意图行动Android应用?

本文发布于:2023-11-27 04:40:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636632.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意图   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!