检查是否特定应用程序在Android设备中可用 [英] Checking if a particular application is available in the android device

查看:190
本文介绍了检查是否特定应用程序在Android设备中可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请我希望创建一个将给予敬酒时,如果它检查通过在Android设备中的应用,如果这样的应用程序安装在设备将通知用户的情况。
请注意,我不希望显示安装的应用程序我只是想创建一个将通过在设备中的所有应用程序会检查条件的列表。
我已经写了下面给出的code,但我似乎没有越来越期望的结果。
请有人可以帮我修改或更好的解决方案。

 字符串的applicationName;
getApplicationName(holder.Text_Name.toString());如果(applicationName.contains(holder.Text_Name.toString())){
    Toast.makeText(getApplicationContext(),应用程序安装,Toast.LENGTH_SHORT).show();
}其他{
    Toast.makeText(getApplicationContext(),应用程序未安装,Toast.LENGTH_SHORT).show();
}}
});}私人无效getApplicationName(字符串TEXT_NAME){    软件包管理系统软件包管理系统= getPackageManager();
    清单< PackageInfo>包= packageManager.getInstalledPackages(0);
    的for(int i = 0; I< packs.size();我++){
        PackageInfo p值= packs.get(ⅰ);
       如果(p.applicationInfo.name == TEXT_NAME)
        的applicationName = TEXT_NAME;    }
}


解决方案

首先,没有必要使用静态变量。你可以建立一个方法,其中传给你正在寻找的应用程序,并通过已安装的应用程序列表中搜索。一旦所需的应用程序是找到可以显示敬酒,然后有..

您可以通过下面链接查看如何找到安装的应用程序

<一个href=\"http://stackoverflow.com/questions/2695746/how-to-get-a-list-of-installed-android-applications-and-pick-one-to-run\">How让安装Android应用程序的列表,并选择一个运行

Please I want to create a condition that will give a toast if when it checks through the applications in the android device will notify the user if such an application is installed in the device. Note that I don't want to display the list of installed applications I just want to create a condition that will check through all the applications in the device. I have written the code given below but I seem not to be getting the desired result. Please can someone help me with the modification or a better solution.

String applicationName;
getApplicationName(holder.Text_Name.toString());

if(applicationName.contains(holder.Text_Name.toString())) {
    Toast.makeText(getApplicationContext(), "Application Installed",Toast.LENGTH_SHORT).show();
} else {
    Toast.makeText(getApplicationContext(), "Application Not Installed",Toast.LENGTH_SHORT).show();
}

}


});

}

private  void getApplicationName(String Text_Name) {

    PackageManager packageManager=getPackageManager();
    List<PackageInfo>packs=packageManager.getInstalledPackages(0);
    for(int i=0;i<packs.size();i++) {
        PackageInfo p=packs.get(i);
       if(p.applicationInfo.name==Text_Name)
        applicationName=Text_Name;

    }
}

解决方案

First of all there is no need to use Static variable. You can build a method, where in pass the application you are looking for and search through the list of applications already installed. Once desired app is find you can show toast then and there..

You can use below link to check how to find installed apps

How to get a list of installed android applications and pick one to run

这篇关于检查是否特定应用程序在Android设备中可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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