我的应用程序应该能够通过 WhatsApp、电子邮件、SMS 等在 TextView 中发送文本。为此,我需要一个已安装的消息应用程序列表。我用 PackageManger 试过,但我得到了所有应用程序。我怎样才能只获得即时消息应用程序?
这是我列出已安装应用程序的代码:
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));
}
}