如何让安装即时通讯应用程序的列表? [英] how to get list of installed instant messenger apps?

查看:325
本文介绍了如何让安装即时通讯应用程序的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序应该能够通过WhatsApp的,电子邮件,短信等。我需要安装Messging应用程序的列表,将文本发送在一个TextView。我与PackageManger尝试过,但我得到的所有应用程序。我怎样才能得到的只有即时消息应用程序?

这是我的code列出已安装的应用程序:

 软件包管理系统软件包管理系统= this.getPackageManager();
    清单< PackageInfo> APPLIST = packageManager.getInstalledPackages(0);
    迭代器< PackageInfo>它= applist.iterator();
    而(it.hasNext()){
    PackageInfo PK =(PackageInfo)it.next();
    如果(PackageManager.PERMISSION_GRANTED ==(packageManager.checkPermission(Manifest.permission.INTERNET,pk.packageName)及packageManager.checkPermission(Manifest.permission.RECEIVE_SMS,pk.packageName)))//检查是否包有INTERNET权限
    {
    myList.add(+ pk.applicationInfo.loadLabel(软件包管理系统));
    }
    }


解决方案

咋办你设法得到你想要的应用程序的列表,然后你有什么打算跟他们做什么?
我认为你需要让Android为以present应用程序的列表,以用户为他们选择他们要处理的文字,根据所执行的操作的应用程序。幸运的是,这是在Android的功能构建。这里是我的发送e-mail功能:

 公共静态无效StartEmailIntent(上下文CX,弦乐EmailAddress的){
    意图电子邮件=新意图(Intent.ACTION_SEND);    email.setType(纯/文);
    email.putExtra(Intent.EXTRA_EMAIL,新的String [] {EmailAddress的});    cx.startActivity(Intent.createChooser(电子邮件,cx.getString(R.string.dlg_sendmail_selectortitle)));
}

正如你可以看到我设置Intent.ACTION_SEND作为动作,然后用Intent.createChooser的Andr​​oid创造了能够处理基于类型和意图的额外的行动应用程序列表。它不应该是很难适应其他操作,如短信,电话等,您可以阅读更多关于它在这里的将内容发送到其他应用程序

希望这有助于...

My app should be able to send the text in a TextView via WhatsApp, Email, SMS etc. For that i need a list of installed Messging Applications. I tried it with the PackageManger but i get all apps. How can i get only the Instant Messaging Apps?

This is my code to list the installed apps:

PackageManager packageManager=this.getPackageManager(); 
    List<PackageInfo> applist=packageManager.getInstalledPackages(0);
    Iterator<PackageInfo> it=applist.iterator();
    while(it.hasNext()){
    PackageInfo pk=(PackageInfo)it.next();
    if(PackageManager.PERMISSION_GRANTED==(packageManager.checkPermission(Manifest.permission.INTERNET, pk.packageName)& packageManager.checkPermission(Manifest.permission.RECEIVE_SMS, pk.packageName))) //checking if the package is having INTERNET permission
    {
    myList.add(""+pk.applicationInfo.loadLabel(packageManager));
    }
    }

解决方案

Supposed you manage to get the list of the apps you want, then what are you going to do with them? I think that you need to let android to present a list of apps to your users for them to choose which application they want to handle the text, depending on the action performed. Fortunately this is a build in feature in Android. Here is my function for sending e-mails:

public static void StartEmailIntent (Context cx, String EmailAddress){
    Intent email = new Intent(Intent.ACTION_SEND);

    email.setType("plain/text");
    email.putExtra(Intent.EXTRA_EMAIL, new String[]{EmailAddress});

    cx.startActivity(Intent.createChooser(email, cx.getString(R.string.dlg_sendmail_selectortitle)));
}

As you can see I am setting Intent.ACTION_SEND as the action and then with the Intent.createChooser android creates a list of applications capable to handle that action based on the type and the extras of the Intent. It shouldn't be hard to adapt other actions like SMS, Phone calls etc. You can read more about it here Sending Content to Other Apps

Hope this helps...

这篇关于如何让安装即时通讯应用程序的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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