Example usage for android.content.pm PackageManager GET_META_DATA

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

Introduction

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

Prototype

int GET_META_DATA

To view the source code for android.content.pm PackageManager GET_META_DATA.

Click Source Link

Document

ComponentInfo flag: return the ComponentInfo#metaData data android.os.Bundle s that are associated with a component.

Usage

From source file:Main.java

/**
 *
 * Gets meta channel.//from  w  w w  .  jav a  2 s. c  om
 *
 * @param activity    the activity
 * @param channelName just like "UMENG_CHANNEL"
 * @return meta channel
 */
public static String getMetaChannel(Context activity, String channelName) {
    String channel = "";
    try {
        ApplicationInfo info = activity.getPackageManager().getApplicationInfo(activity.getPackageName(),
                PackageManager.GET_META_DATA);
        channel = "" + info.metaData.get(channelName);
    } catch (Exception e) {
        e.printStackTrace();
    }
    //        Toast.makeText(activity, "channel is " + channel, Toast.LENGTH_LONG).show();
    return channel;

}

From source file:Main.java

public static String getMetaValue(Context context, String metaKey) {
    Bundle metaData = null;//from w  w  w  .j a  va2  s  . co  m
    String metaValue = null;
    if (context == null || metaKey == null) {
        return null;
    }
    try {
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        if (null != ai) {
            metaData = ai.metaData;
        }
        if (null != metaData) {
            metaValue = metaData.getString(metaKey);
        }
    } catch (NameNotFoundException e) {

    }
    return metaValue;
}

From source file:Main.java

public static Bitmap packageNameToBitmap(PackageManager packageManager, String packageName) {
    try {/* www . ja  v  a 2s. c  om*/
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName,
                PackageManager.GET_META_DATA);
        Resources resources = packageManager.getResourcesForApplication(applicationInfo);
        int appIconResId = applicationInfo.icon;
        return resIdToBitmap(resources, appIconResId);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static String getMetaValue(String metaName) {
    ApplicationInfo appInfo;//ww  w  .  j a  v a2  s . co  m
    String metaValue = null;
    try {
        appInfo = APPLICATION_CONTEXT.getPackageManager()
                .getApplicationInfo(APPLICATION_CONTEXT.getPackageName(), PackageManager.GET_META_DATA);
        metaValue = appInfo.metaData.getString(metaName);
    } catch (NameNotFoundException e) {
        Log.e(TAG, e.getMessage());
    }
    return metaValue;
}

From source file:Main.java

public static void initInstalledAppCache(final Context ctx, boolean forceRefresh) {
    if (sInstalledApps != null && !forceRefresh) {
        return;/*from w w w. j  a  v  a2  s  . c  o  m*/
    }
    final PackageManager pm = ctx.getPackageManager();
    final List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    Map<String, Void> iapps = new HashMap<String, Void>(packages.size());
    for (final ApplicationInfo packageInfo : packages) {
        iapps.put(packageInfo.packageName, null);
    }
    sInstalledApps = iapps;
    sInstalledAppsLastUpdated = System.currentTimeMillis();
}

From source file:Main.java

public static String getMetaValue(Context context, String metaKey) {
    Bundle metaData = null;//from   www.j  a  v  a 2  s  .  com
    String apiKey = null;
    if (context == null || metaKey == null) {
        return null;
    }
    try {
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        if (null != ai) {
            metaData = ai.metaData;
        }
        if (null != metaData) {
            apiKey = metaData.getString(metaKey);
        }
    } catch (NameNotFoundException e) {
        Log.e(TAG, "error " + e.getMessage());
    }
    return apiKey;
}

From source file:Main.java

public static String getAppMetaData(Context context, String archiveFilePath, String name) {
    try {/*w w  w.j  a v  a  2s .c o m*/
        return context.getPackageManager().getPackageArchiveInfo(archiveFilePath,
                PackageManager.GET_META_DATA).applicationInfo.metaData.get(name).toString();
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static String getAppVersionName(Context context, String archiveFilePath) {
    try {//  w ww .  j  ava  2  s . co m
        PackageInfo info = context.getPackageManager().getPackageArchiveInfo(archiveFilePath,
                PackageManager.GET_META_DATA);
        return info.versionName;
    } catch (Exception e) {
        return "";
    }
}

From source file:Main.java

/**
 * Calls {@link Context#startActivity(Intent)} with the given {@link Intent}. If it is
 * <b>implicit</b>, makes sure there is an Activity to handle it. If <b>explicit</b>,
 * will intercept {@link android.content.ActivityNotFoundException}. Can show an error toast on
 * failure.//from  ww w  .ja  va  2 s .  co  m
 *
 * <p> E.g. an implicit intent may fail if e.g. the web browser has been disabled through
 * restricted profiles.
 *
 * @return Whether the {@link Intent} could be handled.
 */

public static String getVersion(Context context) {
    String version;
    try {
        version = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_META_DATA).versionName;
    } catch (PackageManager.NameNotFoundException e) {
        version = "UnknownVersion";
    }
    return version;
}

From source file:Main.java

@TargetApi(16)
static void setAndroidBeam(Activity activity, String packageName) {
    if (Build.VERSION.SDK_INT < 16)
        return;/*from   ww  w . j a  v a 2s.  c o  m*/
    PackageManager pm = activity.getPackageManager();
    NfcAdapter nfcAdapter = getAdapter(activity);
    if (nfcAdapter != null) {
        ApplicationInfo appInfo;
        try {
            appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
            Uri uris[] = { Uri.parse("file://" + appInfo.publicSourceDir), };
            nfcAdapter.setBeamPushUris(uris, activity);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}