android获取应用名称,判断应用是否安装

android获取应用名称方法:

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

public static String getApplicationName() { 
        PackageManager packageManager = null; 
        ApplicationInfo applicationInfo = null; 
        try { 
            packageManager = _activity.getApplicationContext().getPackageManager(); 
            applicationInfo = packageManager.getApplicationInfo(_activity.getPackageName(), 0); 
        } catch (PackageManager.NameNotFoundException e) { 
            applicationInfo = null; 
        } 
        String applicationName =  
        (String) packageManager.getApplicationLabel(applicationInfo); 
        return applicationName; 
    }

判断应用是否安装方法:

import android.content.pm.PackageManager.NameNotFoundException;

public boolean isPlatformInstalled(String packageName)
{
    android.content.pm.ApplicationInfo info = null;
    try 
    {
        info = _activity.getPackageManager().getApplicationInfo(packageName, 0);
        return info != null;
    } 
    catch (NameNotFoundException e) 
    {
        return false;
    }
}

 

你可能感兴趣的:(Android)