如何检查应用程序以前是否已安装

时间:2017-04-04 07:07:23

标签: android android-package-managers

如何检查以前是否已安装该应用?我知道我可以在第一次安装时搜索包管理器类,但是可以通过卸载并重新安装应用程序来重置从此方法返回的值。我正在谈论的不是我的应用程序,例如,如果我想检查亚马逊以前是否已安装在移动设备中,那么如何做到这一点?我搜索了StackOverflow,但没有任何对我有用。

3 个答案:

答案 0 :(得分:1)

试试这可能会有所帮助

//使用我们要检查的包名称         boolean isAppInstalled = appInstalledOrNot(" com.check.application");

    if(isAppInstalled) {
        //This intent will help you to launch if the package is already installed
        Intent LaunchIntent = getPackageManager()
            .getLaunchIntentForPackage("com.check.application");
        startActivity(LaunchIntent);

        Log.i("Application is already installed.");       
    } else {
        // Do whatever we want to do if application not installed
        // For example, Redirect to play store

        Log.i("Application is not currently installed.");
    }
}

private boolean appInstalledOrNot(String uri) {
    PackageManager pm = getPackageManager();
    try {
        pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
    }

    return false;
}

答案 1 :(得分:0)

没有通用的方法来检查设备上是否安装了 应用程序(出于安全原因,您可以想象)。

但是,如果您的目标是特定的应用程序,您可以尝试分析是否在SD卡上有该应用程序的可访问剩余部分。然后,如果安装了应用程序,您的应用程序可以根据文件的存在情况进行检查。

如果您想知道设备上是否安装了某个自己的应用。您可以使用SD卡方法并将文件写入SD卡并使用其他应用程序进行阅读。

答案 2 :(得分:-1)

您可以使用SD卡上的文件来实现此目的:

   File f = new File("path of your file & sdcard location");
    if (f.isDirectory()) {
        // Already installed your application get the file

    }else{
        // First time installed write a file here
        f.mkdir();
    }