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:com.grass.caishi.cc.MyApplication.java

private String getAppName(int pID) {
    String processName = null;//from ww w  . j  av a  2  s .  c om
    ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    List l = am.getRunningAppProcesses();
    Iterator i = l.iterator();
    PackageManager pm = this.getPackageManager();
    while (i.hasNext()) {
        ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next());
        try {
            if (info.pid == pID) {
                CharSequence c = pm.getApplicationLabel(
                        pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
                // Log.d("Process", "Id: "+ info.pid +" ProcessName: "+
                // info.processName +" Label: "+c.toString());
                // processName = c.toString();
                processName = info.processName;
                return processName;
            }
        } catch (Exception e) {
            // Log.d("Process", "Error>> :"+ e.toString());
        }
    }
    return processName;
}

From source file:org.wso2.iot.agent.api.ApplicationManager.java

/**
 * Return the list of the package names of the apps(hidden and visible) that are user owned
 *
 * @return - list of package names of the apps that are not system apps
 *//*from ww  w .ja v a  2s . c o  m*/
public List<String> getAppsOfUser() {
    List<String> packagesInstalledByUser = new ArrayList<>();
    int flags = PackageManager.GET_META_DATA | PackageManager.GET_SHARED_LIBRARY_FILES
            | PackageManager.GET_UNINSTALLED_PACKAGES;
    List<ApplicationInfo> applications = packageManager.getInstalledApplications(flags);
    for (ApplicationInfo appInfo : applications) {
        if (!((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)) {
            packagesInstalledByUser.add(appInfo.packageName);
        }
    }
    return packagesInstalledByUser;
}

From source file:de.quist.app.errorreporter.ExceptionReportService.java

public int getMaximumRetryCount() throws NameNotFoundException {
    try {//  www.  j ava  2  s  .c  o m
        ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(),
                PackageManager.GET_META_DATA);
        return ai.metaData.getInt(META_DATA_MAXIMUM_RETRY_COUNT, DEFAULT_MAXIMUM_RETRY_COUNT);
    } catch (NameNotFoundException e) {
        // Should never happen
        throw e;
    }
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Gets the list of system applications.
 * /* www  .j a v a2s .  co  m*/
 * @return   The list. If error the list will be empty.
 */
public static Set<String> system_getSystemApplicationList(Context context) {
    Set<String> systemApps = new HashSet<String>();

    try {
        final PackageManager pm = context.getPackageManager();
        final List<ApplicationInfo> installedApps = pm.getInstalledApplications(PackageManager.GET_META_DATA);
        for (ApplicationInfo app : installedApps) {
            if (system_isSystemPackage(app)) {
                systemApps.add(app.packageName);
            }
        }

    } catch (Exception e) {
        if (LOG_ENABLE) {
            Log.e(TAG, "Error getting system application list [" + e.getMessage() + "]", e);
        }
    }

    return systemApps;
}

From source file:org.fdroid.fdroid.FDroidApp.java

public void sendViaBluetooth(Activity activity, int resultCode, String packageName) {
    if (resultCode == Activity.RESULT_CANCELED) {
        return;//  ww  w .j  a v  a 2s . c o m
    }
    String bluetoothPackageName = null;
    String className = null;
    boolean found = false;
    Intent sendBt = null;
    try {
        PackageManager pm = getPackageManager();
        ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        sendBt = new Intent(Intent.ACTION_SEND);
        // The APK type is blocked by stock Android, so use zip
        // sendBt.setType("application/vnd.android.package-archive");
        sendBt.setType("application/zip");
        sendBt.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + appInfo.publicSourceDir));
        // not all devices have the same Bluetooth Activities, so
        // let's find it
        for (ResolveInfo info : pm.queryIntentActivities(sendBt, 0)) {
            bluetoothPackageName = info.activityInfo.packageName;
            if ("com.android.bluetooth".equals(bluetoothPackageName)
                    || "com.mediatek.bluetooth".equals(bluetoothPackageName)) {
                className = info.activityInfo.name;
                found = true;
                break;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Could not get application info to send via bluetooth", e);
        found = false;
    }
    if (sendBt != null) {
        if (found) {
            sendBt.setClassName(bluetoothPackageName, className);
            activity.startActivity(sendBt);
        } else {
            Toast.makeText(this, R.string.bluetooth_activity_not_found, Toast.LENGTH_SHORT).show();
            activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send)));
        }
    }
}

From source file:de.quist.app.errorreporter.ExceptionReportService.java

public int getMaximumBackoffExponent() throws NameNotFoundException {
    try {//from   w ww  . j  av a 2 s .  co  m
        ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(),
                PackageManager.GET_META_DATA);
        return ai.metaData.getInt(META_DATA_MAXIMUM_BACKOFF_EXPONENT, DEFAULT_MAXIMUM_BACKOFF_EXPONENT);
    } catch (NameNotFoundException e) {
        // Should never happen
        throw e;
    }
}

From source file:com.jtechme.apphub.FDroidApp.java

public void sendViaBluetooth(Activity activity, int resultCode, String packageName) {
    if (resultCode == Activity.RESULT_CANCELED)
        return;//from w  w  w . j a  va  2 s . c o m
    String bluetoothPackageName = null;
    String className = null;
    boolean found = false;
    Intent sendBt = null;
    try {
        PackageManager pm = getPackageManager();
        ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        sendBt = new Intent(Intent.ACTION_SEND);
        // The APK type is blocked by stock Android, so use zip
        // sendBt.setType("application/vnd.android.package-archive");
        sendBt.setType("application/zip");
        sendBt.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + appInfo.publicSourceDir));
        // not all devices have the same Bluetooth Activities, so
        // let's find it
        for (ResolveInfo info : pm.queryIntentActivities(sendBt, 0)) {
            bluetoothPackageName = info.activityInfo.packageName;
            if ("com.android.bluetooth".equals(bluetoothPackageName)
                    || "com.mediatek.bluetooth".equals(bluetoothPackageName)) {
                className = info.activityInfo.name;
                found = true;
                break;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Could not get application info to send via bluetooth", e);
        found = false;
    }
    if (sendBt != null) {
        if (found) {
            sendBt.setClassName(bluetoothPackageName, className);
            activity.startActivity(sendBt);
        } else {
            Toast.makeText(this, R.string.bluetooth_activity_not_found, Toast.LENGTH_SHORT).show();
            activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send)));
        }
    }
}

From source file:pffy.mobile.flax.FlaxActivity.java

private String getVersionInfo() {

    PackageInfo info;/*from   w  w w . ja  va2s  .c  o m*/
    String str = "";

    try {
        info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
        str += "v" + info.versionName + " (r" + info.versionCode + ")";
    } catch (NameNotFoundException nnfe) {
        str += "No version info.";
    }

    str += CRLF + getString(R.string.msg_authors);
    return str;
}

From source file:net.lp.actionbarpoirot.helpers.DualNavUtils.java

/**
 * Return the fully qualified class name of a source activity's parent
 * activity as specified by a {@link #PARENT_ACTIVITY} &lt;meta-data&gt;
 * element within the activity element in the application's manifest. The
 * source activity is provided by componentName.
 * /*from ww  w. j  a  v  a 2  s  .  c  o  m*/
 * @param context
 *            Context for looking up the activity component for the source
 *            activity
 * @param componentName
 *            ComponentName for the source Activity
 * @return The fully qualified class name of sourceActivity's parent
 *         activity or null if it was not specified
 */
public static String getParentActivityName(Context context, ComponentName componentName)
        throws NameNotFoundException {
    final PackageManager pm = context.getPackageManager();
    final ActivityInfo info = pm.getActivityInfo(componentName, PackageManager.GET_META_DATA);

    return getParentActivityNameInner(context, info);
}

From source file:de.quist.app.errorreporter.ExceptionReportService.java

public Set<String> getFieldsToSend() throws NameNotFoundException {
    try {//  w  w  w  .ja  va  2  s  . co  m
        HashSet<String> result = new HashSet<String>();
        ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(),
                PackageManager.GET_META_DATA);
        String fields = ai.metaData.getString(META_DATA_FIELDS_TO_SEND);
        if (fields == null)
            fields = DEFAULT_FIELDS_TO_SEND;
        StringTokenizer st = new StringTokenizer(fields, ",");
        while (st.hasMoreTokens()) {
            result.add(st.nextToken());
        }
        return result;
    } catch (NameNotFoundException e) {
        // Should never happen
        throw e;
    }
}