Example usage for android.content.pm PackageManager getApplicationInfo

List of usage examples for android.content.pm PackageManager getApplicationInfo

Introduction

In this page you can find the example usage for android.content.pm PackageManager getApplicationInfo.

Prototype

public abstract ApplicationInfo getApplicationInfo(String packageName, @ApplicationInfoFlags int flags)
        throws NameNotFoundException;

Source Link

Document

Retrieve all of the information we know about a particular package/application.

Usage

From source file:Main.java

public static String getApplicationName(Context app) {
    PackageManager pm;
    ApplicationInfo ai;/*from  ww w .j a v a 2s. c om*/
    try {
        pm = app.getPackageManager();
        ai = pm.getApplicationInfo(app.getPackageName(), 0);
        return pm.getApplicationLabel(ai).toString();
    } catch (Exception e) {
        e.printStackTrace();
        return app.getPackageName();
    }
}

From source file:Main.java

public static boolean hasShortcut(Context cx) {
    boolean result = false;
    String title = null;//  w  w w . j av  a2  s  .c om
    try {
        final PackageManager pm = cx.getPackageManager();
        title = pm.getApplicationLabel(pm.getApplicationInfo(cx.getPackageName(), PackageManager.GET_META_DATA))
                .toString();
    } catch (Exception e) {
        e.printStackTrace();
    }

    final String AUTHORITY;
    if (android.os.Build.VERSION.SDK_INT < 8) {
        AUTHORITY = "com.android.launcher.settings";
    } else {
        AUTHORITY = "com.android.launcher2.settings";
    }
    final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true");
    final Cursor c = cx.getContentResolver().query(CONTENT_URI, null, "title=?", new String[] { title }, null);
    if (c != null && c.moveToFirst()) {
        c.close();
        result = true;
    }
    return result;
}

From source file:Main.java

public static boolean isDebug(Context context) {
    PackageManager pm = context.getPackageManager();
    try {/*from   ww  w . j av a  2s  .  c o  m*/
        ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(), 0);
        return (applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

public static int getUid(Context context, String packageName) {
    int uid = -1;
    PackageManager packageManager = context.getPackageManager();
    try {//w  ww . j a v a2s .  co  m
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
        uid = applicationInfo.uid;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return uid;
}

From source file:Main.java

/**
 * Get give package app install date.//from  www  . ja  v a2  s.com
 * 
 * @param context Object of {@link Context}.
 * @param pkg Package name.
 * @return Measured in milliseconds since January 1st, 1970, midnight. Returns 0 if the file does not exist.
 */
public final static long getAppInstallDate(Context context, String pkg) {
    if (null == context || null == pkg) {
        return System.currentTimeMillis();
    }

    PackageManager pm = context.getPackageManager();
    try {
        ApplicationInfo info = pm.getApplicationInfo(pkg, 0);

        // 2.3(API level 9) ApplicationInfo have a method to get install time.
        // but we can't use it. (for support 2.2 -_-||).
        File file = new File(info.sourceDir);
        return file.lastModified();

    } catch (Exception e) {
        e.printStackTrace();
        return System.currentTimeMillis();
    }
}

From source file:Main.java

public static String getAppName(Context context) {
    PackageManager packageManager = context.getPackageManager();
    try {//from   w  w  w  . j  a va  2s .c o  m
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
        appName = (String) packageManager.getApplicationLabel(applicationInfo);
        if (appName == null)
            appName = "unknown";
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return appName;
}

From source file:Main.java

public static String GetAppName(Activity act) {
    final PackageManager pm = act.getApplicationContext().getPackageManager();

    ApplicationInfo ai;//from  w ww  . java  2  s.c o m
    try {
        ai = pm.getApplicationInfo(act.getPackageName(), 0);
    } catch (final NameNotFoundException e) {
        ai = null;
    }
    final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "unknown");
    return applicationName;
}

From source file:Main.java

public static String getAppName(Context context) {
    PackageManager packageManager = context.getPackageManager();
    ApplicationInfo appInfo = null;//from  ww  w .  ja v  a  2s  . c om
    try {
        appInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
    } catch (NameNotFoundException e) {

    }
    return appInfo == null ? "null" : packageManager.getApplicationLabel(appInfo).toString();
}

From source file:Main.java

public static String getAppName(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    String appName = null;//from w ww  . j av  a  2 s.  c o  m
    try {
        ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName, 0);
        appName = String.valueOf(pm.getApplicationLabel(applicationInfo));
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return appName;
}

From source file:Main.java

public static String getApplicationName(final Context context) {
    String appName = "";

    PackageManager packageManager = context.getPackageManager();
    try {/*from   ww w. java2 s  .  co  m*/
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        appName = packageManager.getApplicationLabel(applicationInfo).toString();
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    return appName;
}