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

2023-09-07 23:55:13 作者:伴着音樂入夢

我想分享短信低谷的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){        //你至少有一个活动来处理这个意图    }其他{        //没有活动处理的意图。    } 

论文研究 基于用户意图的Android程序异常行为识别.pdf 其它代码类资源 CSDN下载

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.
    }