Вопрос

Could I know If there is a specific app installed in the phone programmatically? My app would make a process in one way or in other depending on that. How could I get this information?

Thanks!!

Это было полезно?

Решение

private boolean isAppInstalled(String packageName) {
    PackageManager pm = getPackageManager();
    boolean installed = false;
    try {
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        installed = false;
    }
    return installed;
}

Другие советы

You must know the package name to check weather the application is installed or not

say if package name is like com.myapp.name

use the following to existence

boolean isExists;
try
        {
            getPackageManager().getPackageInfo("com.myapp.name", PackageManager.GET_ACTIVITIES);
            isExists = true;
        }
        catch(NameNotFoundException e)
        {
            isExists = false;
            // Sep 11, 2013 8:39:47 PM
            Log.e("Exception", "NameNotFoundException" + String.valueOf(e.getMessage()));
            e.printStackTrace();
        }

Must use try catch around to handling expected error when NameNotFoundException is thrown

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top