如何检测,可以处理请求的意图行动Android应用? [英] How to detect android apps that can handle requested Intent action?

查看:167
本文介绍了如何检测,可以处理请求的意图行动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应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆