PackageManager getPackageInfo - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for PackageManager getPackageInfo method.

This code example shows how to use the following methods:getPackageInfo
    } 
 
    public static String getApplicationVersionString(Context context) {
        try { 
            PackageManager pm = context.getPackageManager();
            PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
            return "v" + info.versionName;
        } catch (Exception e) {
            e.printStackTrace();
            return null; 
        } 
    } 
 
    public static String createDiagnosis(Activity context, Exception error) {
        StringBuilder sb = new StringBuilder();
 
        sb.append("Application version: " + getApplicationVersionString(context) + "\n");
        sb.append("Device locale: " + Locale.getDefault().toString() + "\n\n");
        sb.append("Android ID: " + getAndroidId(context, "n/a"));
 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPackageInfo
    } 
 
    public static String getApplicationVersionString(Context context) {
        try { 
            PackageManager pm = context.getPackageManager();
            PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
            return "v" + info.versionName;
        } catch (Exception e) {
            e.printStackTrace();
            return null; 
        } 
    } 
 
    public static String createDiagnosis(Activity context, Exception error) {
        StringBuilder sb = new StringBuilder();
 
        sb.append("Application version: " + getApplicationVersionString(context) + "\n");
        sb.append("Device locale: " + Locale.getDefault().toString() + "\n\n");
        sb.append("Android ID: " + getAndroidId(context, "n/a"));
 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPackageInfo
        CrashManagerConstants.PHONE_MODEL = android.os.Build.MODEL;
        CrashManagerConstants.PHONE_MANUFACTURER = android.os.Build.MANUFACTURER;
 
        PackageManager packageManager = context.getPackageManager();
        try { 
            PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            CrashManagerConstants.APP_VERSION = "" + packageInfo.versionCode;
            CrashManagerConstants.APP_PACKAGE = packageInfo.packageName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        } 
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getActivityInfo, getPackageInfo
        ComponentName componentName = searchable.getSearchActivity();
        if (DBG) Log.d(TAG, "created Searchable for " + componentName);
        mSearchable = searchable;
        mName = componentName.flattenToShortString();
        PackageManager pm = context.getPackageManager();
        mActivityInfo = pm.getActivityInfo(componentName, 0);
        PackageInfo pkgInfo = pm.getPackageInfo(componentName.getPackageName(), 0);
        mVersionCode = pkgInfo.versionCode;
    } 
 
    public SearchableInfo getSearchableInfo() {
        return mSearchable;
    } 
 
    /** 
     * Checks if the current process can read the suggestion provider in this source. 
     */ 
    public boolean canRead() { 
        String authority = mSearchable.getSuggestAuthority();
        if (authority == null) {
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPackageInfo, getClass
        PackageManager packageManager = mContext.getPackageManager();
 
        String foundAppVersionName = null;
        Integer foundAppVersionCode = null;
        try { 
            PackageInfo packageInfo = packageManager.getPackageInfo(mContext.getPackageName(), 0);
            foundAppVersionName = packageInfo.versionName;
            foundAppVersionCode = packageInfo.versionCode;
        } catch (NameNotFoundException e) {
            Log.w(LOGTAG, "System information constructed with a context that apparently doesn't exist.");
        } 
 
        mAppVersionName = foundAppVersionName;
        mAppVersionCode = foundAppVersionCode;
 
        // We can't count on these features being available, since we need to 
        // run on old devices. Thus, the reflection fandango below... 
        Class<? extends PackageManager> packageManagerClass = packageManager.getClass();
 
        Method hasSystemFeatureMethod = null;

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPackageInfo
		boolean debug = (appInfo.flags & FLAG_DEBUGGABLE) != 0;
		return debug;
	} 
 
	public String getSignature(String pkgName) throws NameNotFoundException {
		PackageInfo pi = pkgMngr.getPackageInfo(pkgName, GET_SIGNATURES);
		String signature = pi.signatures[0].toCharsString();
		return signature;
	} 
 
	public boolean doSignaturesMatch(String pkg1, String pkg2) {
		boolean match = pkgMngr.checkSignatures(pkg1, pkg2) == SIGNATURE_MATCH;
		return match;
	} 
 
	public boolean isInstalledFromMarket(String pkgName)
			throws NameNotFoundException { 
		String installerPkg = pkgMngr.getInstallerPackageName(pkgName);
		boolean installedFromMarket = "com.google.android.feedback"
				.equals(installerPkg);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPackageInfo
This code example shows how to use the following methods:getPackageInfo
 
	public static int getAmazonVersion(Context ctx) {
		PackageManager pm = ctx.getPackageManager();
		int result = -1;
		try { 
			PackageInfo pi = pm.getPackageInfo("com.amazon.mp3", PackageManager.GET_ACTIVITIES);
			result = pi.versionCode;
		} catch (Exception e) {
			result = -1;
		} 
		return result;
	} 
 
	public static void searchForTrack(Context ctx, String artist, String track) {
		String query = artist + " " + track;
		int searchType = 0;
		Intent intent;
		try { 
			intent = new Intent(ACTION_EXTERNAL_EVENT);
			intent.putExtra(EXTRA_EXTERNAL_EVENT_TYPE, TYPE_SEARCH);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getApplicationInfo, getApplicationLabel, getPackageInfo
This code example shows how to use the following methods:getPackageInfo
		} 
 
		try {			 
			String packageName = context.getPackageName();
			PackageManager packageManager = context.getPackageManager();
			versionName = packageManager.getPackageInfo(packageName, 0).versionName;
		} catch (NameNotFoundException e) { 
			Logger.debug(e.getMessage(), e);
		} 
		 
		return versionName;
	} 
 
	public static int getVersionCode(Context context) {
		int versionCode = 0;
		if (context == null) {
			return versionCode;
		} 
 
		try {			 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related PackageManager getPackageInfo Questions & Answers:

getPackageInfo Method Overview
Retrieve overall information about an application package that is installed on the system.
See Code Examples for other Android PackageManager Methods: