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:net.momodalo.app.vimtouch.VimTouch.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_INSTALL) {
        if (checkVimRuntime()) {
            PackageInfo info;/*w  ww  .j a  v  a2  s.co m*/
            SharedPreferences.Editor editor = mPrefs.edit();

            try {
                info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
                editor.putLong(VimSettings.LASTVERSION_KEY, info.versionCode);
                editor.commit();
            } catch (Exception e) {
            }

            startEmulator();
            updatePrefs();
            mEmulatorView.onResume();
        }
    } else if (requestCode == REQUEST_OPEN) {
        /*
        if (resultCode == Activity.RESULT_OK) {
        String filePath = data.getStringExtra(FileDialog.RESULT_PATH);
        mUrl = filePath;
        }
        */
    }
}

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

/**
 * Creates a application informative dialog with options to
 * uninstall/launch or cancel./*from ww w.  j  a  va2s .  co  m*/
 * 
 * @param context
 * @param appPackage
 */
public static void appInfo_getLaunchUninstallDialog(final Context context, String appPackage) {

    try {

        final PackageManager packageManager = context.getPackageManager();
        final PackageInfo app = packageManager.getPackageInfo(appPackage, PackageManager.GET_META_DATA);

        AlertDialog dialog = new AlertDialog.Builder(context).create();

        dialog.setTitle(app.applicationInfo.loadLabel(packageManager));

        String description = null;
        if (app.applicationInfo.loadDescription(packageManager) != null) {
            description = app.applicationInfo.loadDescription(packageManager).toString();
        }

        String msg = app.applicationInfo.loadLabel(packageManager) + "\n\n" + "Version " + app.versionName
                + " (" + app.versionCode + ")" + "\n" + (description != null ? (description + "\n") : "")
                + app.applicationInfo.sourceDir + "\n" + appInfo_getSize(app.applicationInfo.sourceDir);
        dialog.setMessage(msg);

        dialog.setCancelable(true);
        dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Uninstall", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent intent = new Intent(Intent.ACTION_DELETE);
                intent.setData(Uri.parse("package:" + app.packageName));
                context.startActivity(intent);
            }
        });
        dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Launch", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent i = packageManager.getLaunchIntentForPackage(app.packageName);
                context.startActivity(i);
            }
        });

        dialog.show();
    } catch (Exception e) {
        if (LOG_ENABLE) {
            Log.e(TAG, "Dialog could not be made for the specified application '" + appPackage + "'. ["
                    + e.getMessage() + "].", e);
        }
    }
}

From source file:com.localytics.phonegap.LocalyticsPlugin.java

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    if (action.equals("integrate")) {
        String localyticsKey = (args.length() == 1 ? args.getString(0) : null);
        Localytics.integrate(cordova.getActivity().getApplicationContext(), localyticsKey);
        callbackContext.success();/*from  ww w.  j  a va  2  s.c  o m*/
        return true;
    } else if (action.equals("upload")) {
        Localytics.upload();
        callbackContext.success();
        return true;
    } else if (action.equals("autoIntegrate")) {
        /* App-key is read from meta-data LOCALYTICS_APP_KEY in AndroidManifest */
        Application app = cordova.getActivity().getApplication();
        app.registerActivityLifecycleCallbacks(
                new LocalyticsActivityLifecycleCallbacks(app.getApplicationContext()));
        callbackContext.success();
        return true;
    } else if (action.equals("openSession")) {
        Localytics.openSession();
        callbackContext.success();
        return true;
    } else if (action.equals("closeSession")) {
        Localytics.closeSession();
        callbackContext.success();
        return true;
    } else if (action.equals("tagEvent")) {
        if (args.length() == 3) {
            String name = args.getString(0);
            if (name != null && name.length() > 0) {
                JSONObject attributes = null;
                if (!args.isNull(1)) {
                    attributes = args.getJSONObject(1);
                }
                HashMap<String, String> a = null;
                if (attributes != null && attributes.length() > 0) {
                    a = new HashMap<String, String>();
                    Iterator<?> keys = attributes.keys();
                    while (keys.hasNext()) {
                        String key = (String) keys.next();
                        String value = attributes.getString(key);
                        a.put(key, value);
                    }
                }
                int customerValueIncrease = args.getInt(2);
                Localytics.tagEvent(name, a, customerValueIncrease);
                callbackContext.success();
            } else {
                callbackContext.error("Expected non-empty name argument.");
            }
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("tagScreen")) {
        String name = args.getString(0);
        if (name != null && name.length() > 0) {
            Localytics.tagScreen(name);
            callbackContext.success();
        } else {
            callbackContext.error("Expected non-empty name argument.");
        }
        return true;
    } else if (action.equals("setCustomDimension")) {
        if (args.length() == 2) {
            int index = args.getInt(0);
            String value = null;
            if (!args.isNull(1)) {
                value = args.getString(1);
            }
            Localytics.setCustomDimension(index, value);
            callbackContext.success();
        } else {
            callbackContext.error("Expected two arguments.");
        }
        return true;
    } else if (action.equals("getCustomDimension")) {
        final int index = args.getInt(0);
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                String value = Localytics.getCustomDimension(index);
                callbackContext.success(value);
            }
        });
        return true;
    } else if (action.equals("setOptedOut")) {
        boolean enabled = args.getBoolean(0);
        Localytics.setOptedOut(enabled);
        callbackContext.success();
        return true;
    } else if (action.equals("isOptedOut")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                boolean enabled = Localytics.isOptedOut();
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, enabled));
            }
        });
        return true;
    } else if (action.equals("setProfileAttribute")) {
        if (args.length() == 3) {
            String errorString = null;

            String attributeName = args.getString(0);
            Object attributeValue = args.get(1);
            String scope = args.getString(2);

            if (attributeValue instanceof Integer) {
                Localytics.setProfileAttribute(attributeName, (Integer) attributeValue, getProfileScope(scope));
            } else if (attributeValue instanceof String) {
                Localytics.setProfileAttribute(attributeName, (String) attributeValue, getProfileScope(scope));
            } else if (attributeValue instanceof Date) {
                Localytics.setProfileAttribute(attributeName, (Date) attributeValue, getProfileScope(scope));
            } else if (attributeValue instanceof JSONArray) {
                JSONArray array = (JSONArray) attributeValue;
                Object item = getInitialItem(array);
                if (item instanceof Integer) {
                    long[] longs = buildLongArray(array);
                    if (longs != null) {
                        Localytics.setProfileAttribute(attributeName, longs, getProfileScope(scope));
                    } else {
                        errorString = ERROR_INVALID_ARRAY;
                    }
                } else if (item instanceof String) {
                    if (parseISO8601Date((String) item) != null) {
                        Date[] dates = buildDateArray(array);
                        if (dates != null) {
                            Localytics.addProfileAttributesToSet(attributeName, dates, getProfileScope(scope));
                        } else {
                            errorString = ERROR_INVALID_ARRAY;
                        }
                    } else {
                        String[] strings = buildStringArray(array);
                        if (strings != null) {
                            Localytics.addProfileAttributesToSet(attributeName, strings,
                                    getProfileScope(scope));
                        } else {
                            errorString = ERROR_INVALID_ARRAY;
                        }
                    }
                }
            } else {
                errorString = ERROR_UNSUPPORTED_TYPE;
            }

            if (errorString != null) {
                callbackContext.error(errorString);
            } else {
                callbackContext.success();
            }
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("addProfileAttributesToSet")) {
        if (args.length() == 3) {
            String errorString = null;

            String attributeName = args.getString(0);
            Object attributeValue = args.get(1);
            String scope = args.getString(2);

            if (attributeValue instanceof JSONArray) {
                JSONArray array = (JSONArray) attributeValue;
                Object item = getInitialItem(array);
                if (item instanceof Integer) {
                    long[] longs = buildLongArray(array);
                    if (longs != null) {
                        Localytics.addProfileAttributesToSet(attributeName, longs, getProfileScope(scope));
                    } else {
                        errorString = ERROR_INVALID_ARRAY;
                    }
                } else if (item instanceof String) {
                    // Check if date string first
                    if (parseISO8601Date((String) item) != null) {
                        Date[] dates = buildDateArray(array);
                        if (dates != null) {
                            Localytics.addProfileAttributesToSet(attributeName, dates, getProfileScope(scope));
                        } else {
                            errorString = ERROR_INVALID_ARRAY;
                        }
                    } else {
                        String[] strings = buildStringArray(array);
                        if (strings != null) {
                            Localytics.addProfileAttributesToSet(attributeName, strings,
                                    getProfileScope(scope));
                        } else {
                            errorString = ERROR_INVALID_ARRAY;
                        }
                    }
                }
            } else {
                errorString = ERROR_UNSUPPORTED_TYPE;
            }

            if (errorString != null) {
                callbackContext.error(errorString);
            } else {
                callbackContext.success();
            }
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("removeProfileAttributesFromSet")) {
        if (args.length() == 3) {
            String errorString = null;

            String attributeName = args.getString(0);
            Object attributeValue = args.get(1);
            String scope = args.getString(2);
            if (attributeValue instanceof JSONArray) {
                JSONArray array = (JSONArray) attributeValue;
                Object item = getInitialItem(array);
                if (item instanceof Integer) {
                    long[] longs = buildLongArray(array);
                    if (longs != null) {
                        Localytics.removeProfileAttributesFromSet(attributeName, longs, getProfileScope(scope));
                    } else {
                        errorString = ERROR_INVALID_ARRAY;
                    }
                } else if (item instanceof String) {
                    if (parseISO8601Date((String) item) != null) {
                        Date[] dates = buildDateArray(array);
                        if (dates != null) {
                            Localytics.addProfileAttributesToSet(attributeName, dates, getProfileScope(scope));
                        } else {
                            errorString = ERROR_INVALID_ARRAY;
                        }
                    } else {
                        String[] strings = buildStringArray(array);
                        if (strings != null) {
                            Localytics.addProfileAttributesToSet(attributeName, strings,
                                    getProfileScope(scope));
                        } else {
                            errorString = ERROR_INVALID_ARRAY;
                        }
                    }
                }
            } else {
                errorString = ERROR_UNSUPPORTED_TYPE;
            }

            if (errorString != null) {
                callbackContext.error(errorString);
            } else {
                callbackContext.success();
            }
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("incrementProfileAttribute")) {
        if (args.length() == 3) {
            String attributeName = args.getString(0);
            long incrementValue = args.getLong(1);
            String scope = args.getString(2);

            Localytics.incrementProfileAttribute(attributeName, incrementValue, getProfileScope(scope));
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("decrementProfileAttribute")) {
        if (args.length() == 3) {
            String attributeName = args.getString(0);
            long decrementValue = args.getLong(1);
            String scope = args.getString(2);

            Localytics.decrementProfileAttribute(attributeName, decrementValue, getProfileScope(scope));
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("deleteProfileAttribute")) {
        if (args.length() == 2) {
            String attributeName = args.getString(0);
            String scope = args.getString(1);

            Localytics.deleteProfileAttribute(attributeName, getProfileScope(scope));
        } else {
            callbackContext.error("Expected three arguments.");
        }
        return true;
    } else if (action.equals("setIdentifier")) {
        if (args.length() == 2) {
            String key = args.getString(0);
            if (key != null && key.length() > 0) {
                String value = null;
                if (!args.isNull(1)) {
                    value = args.getString(1);
                }
                Localytics.setIdentifier(key, value);
                callbackContext.success();
            } else {
                callbackContext.error("Expected non-empty key argument.");
            }
        } else {
            callbackContext.error("Expected two arguments.");
        }
        return true;
    } else if (action.equals("setCustomerId")) {
        String id = null;
        if (!args.isNull(0)) {
            id = args.getString(0);
        }
        Localytics.setCustomerId(id);
        callbackContext.success();
        return true;
    } else if (action.equals("setCustomerFullName")) {
        String fullName = null;
        if (!args.isNull(0)) {
            fullName = args.getString(0);
        }
        Localytics.setCustomerFullName(fullName);
        callbackContext.success();
        return true;
    } else if (action.equals("setCustomerFirstName")) {
        String firstName = null;
        if (!args.isNull(0)) {
            firstName = args.getString(0);
        }
        Localytics.setCustomerFirstName(firstName);
        callbackContext.success();
        return true;
    } else if (action.equals("setCustomerLastName")) {
        String lastName = null;
        if (!args.isNull(0)) {
            lastName = args.getString(0);
        }
        Localytics.setCustomerLastName(lastName);
        callbackContext.success();
        return true;
    } else if (action.equals("setCustomerEmail")) {
        String email = null;
        if (!args.isNull(0)) {
            email = args.getString(0);
        }
        Localytics.setCustomerEmail(email);
        callbackContext.success();
        return true;
    } else if (action.equals("setLocation")) {
        if (args.length() == 2) {
            Location location = new Location("");
            location.setLatitude(args.getDouble(0));
            location.setLongitude(args.getDouble(1));

            Localytics.setLocation(location);
            callbackContext.success();
        } else {
            callbackContext.error("Expected two arguments.");
        }
        return true;
    } else if (action.equals("registerPush")) {
        String senderId = null;

        try {
            PackageManager pm = cordova.getActivity().getPackageManager();
            ApplicationInfo ai = pm.getApplicationInfo(cordova.getActivity().getPackageName(),
                    PackageManager.GET_META_DATA);
            Bundle metaData = ai.metaData;
            senderId = metaData.getString(PROP_SENDER_ID);
        } catch (PackageManager.NameNotFoundException e) {
            //No-op
        }

        Localytics.registerPush(senderId);
        callbackContext.success();
        return true;
    } else if (action.equals("setPushDisabled")) {
        boolean enabled = args.getBoolean(0);
        Localytics.setPushDisabled(enabled);
        callbackContext.success();
        return true;
    } else if (action.equals("isPushDisabled")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                boolean enabled = Localytics.isPushDisabled();
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, enabled));
            }
        });
        return true;
    } else if (action.equals("setTestModeEnabled")) {
        boolean enabled = args.getBoolean(0);
        Localytics.setTestModeEnabled(enabled);
        callbackContext.success();
        return true;
    } else if (action.equals("isTestModeEnabled")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                boolean enabled = Localytics.isTestModeEnabled();
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, enabled));
            }
        });
        return true;
    } else if (action.equals("setInAppMessageDismissButtonImageWithName")) {
        //No-op
        return true;
    } else if (action.equals("setInAppMessageDismissButtonLocation")) {
        //No-op
        return true;
    } else if (action.equals("getInAppMessageDismissButtonLocation")) {
        //No-op
        return true;
    } else if (action.equals("triggerInAppMessage")) {
        //No-op
        return true;
    } else if (action.equals("dismissCurrentInAppMessage")) {
        //No-op
        return true;
    } else if (action.equals("setLoggingEnabled")) {
        boolean enabled = args.getBoolean(0);
        Localytics.setLoggingEnabled(enabled);
        callbackContext.success();
        return true;
    } else if (action.equals("isLoggingEnabled")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                boolean enabled = Localytics.isLoggingEnabled();
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, enabled));
            }
        });
        return true;
    } else if (action.equals("setSessionTimeoutInterval")) {
        int seconds = args.getInt(0);
        Localytics.setSessionTimeoutInterval(seconds);
        callbackContext.success();
        return true;
    } else if (action.equals("getSessionTimeoutInterval")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                long timeout = Localytics.getSessionTimeoutInterval();
                callbackContext.success(Long.valueOf(timeout).toString());
            }
        });
        return true;
    } else if (action.equals("getInstallId")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                String result = Localytics.getInstallId();
                callbackContext.success(result);
            }
        });
        return true;
    } else if (action.equals("getAppKey")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                String result = Localytics.getAppKey();
                callbackContext.success(result);
            }
        });

        return true;
    } else if (action.equals("getLibraryVersion")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                String result = Localytics.getLibraryVersion();
                callbackContext.success(result);
            }
        });
        return true;
    }
    return false;
}

From source file:io.flutter.embedding.android.FlutterActivity.java

/**
 * The Dart entrypoint that will be executed as soon as the Dart snapshot is loaded.
 * <p>/*from w ww  .j av a2s. c  om*/
 * This preference can be controlled with 2 methods:
 * <ol>
 *   <li>Pass a {@code String} as {@link #EXTRA_DART_ENTRYPOINT} with the launching {@code Intent}, or</li>
 *   <li>Set a {@code <meta-data>} called {@link #DART_ENTRYPOINT_META_DATA_KEY} for this
 *       {@code Activity} in the Android manifest.</li>
 * </ol>
 * If both preferences are set, the {@code Intent} preference takes priority.
 * <p>
 * The reason that a {@code <meta-data>} preference is supported is because this {@code Activity}
 * might be the very first {@code Activity} launched, which means the developer won't have
 * control over the incoming {@code Intent}.
 * <p>
 * Subclasses may override this method to directly control the Dart entrypoint.
 */
@NonNull
protected String getDartEntrypoint() {
    if (getIntent().hasExtra(EXTRA_DART_ENTRYPOINT)) {
        return getIntent().getStringExtra(EXTRA_DART_ENTRYPOINT);
    }

    try {
        ActivityInfo activityInfo = getPackageManager().getActivityInfo(getComponentName(),
                PackageManager.GET_META_DATA | PackageManager.GET_ACTIVITIES);
        Bundle metadata = activityInfo.metaData;
        String desiredDartEntrypoint = metadata != null ? metadata.getString(DART_ENTRYPOINT_META_DATA_KEY)
                : null;
        return desiredDartEntrypoint != null ? desiredDartEntrypoint : DEFAULT_DART_ENTRYPOINT;
    } catch (PackageManager.NameNotFoundException e) {
        return DEFAULT_DART_ENTRYPOINT;
    }
}

From source file:com.roymam.android.nilsplus.ui.NiLSActivity.java

private boolean isPackageInstalled(String packagename) {
    PackageManager pm = getApplicationContext().getPackageManager();
    try {/*  w ww .j  a  va2 s. co m*/
        pm.getPackageInfo(packagename, PackageManager.GET_META_DATA);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:com.facebook.Settings.java

/**
 * Loads default values for certain settings from an application's AndroidManifest.xml metadata, if possible.
 * If values have been explicitly set for a particular setting, they will not be overwritten. The following
 * settings are currently loaded from metadata: APPLICATION_ID_PROPERTY, CLIENT_TOKEN_PROPERTY
 * @param context the Context to use for loading metadata
 *//*ww  w . j a  v a  2 s .  c  o  m*/
public static void loadDefaultsFromMetadata(Context context) {
    defaultsLoaded = true;

    if (context == null) {
        return;
    }

    ApplicationInfo ai = null;
    try {
        ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        return;
    }

    if (ai == null || ai.metaData == null) {
        return;
    }

    if (applicationId == null) {
        applicationId = ai.metaData.getString(APPLICATION_ID_PROPERTY);
    }
    if (appClientToken == null) {
        appClientToken = ai.metaData.getString(CLIENT_TOKEN_PROPERTY);
    }
}

From source file:io.flutter.embedding.android.FlutterActivity.java

/**
 * The initial route that a Flutter app will render upon loading and executing its Dart code.
 * <p>/*from w w w .j ava 2 s  .c  om*/
 * This preference can be controlled with 2 methods:
 * <ol>
 *   <li>Pass a boolean as {@link #EXTRA_INITIAL_ROUTE} with the launching {@code Intent}, or</li>
 *   <li>Set a {@code <meta-data>} called {@link #INITIAL_ROUTE_META_DATA_KEY} for this
 *    {@code Activity} in the Android manifest.</li>
 * </ol>
 * If both preferences are set, the {@code Intent} preference takes priority.
 * <p>
 * The reason that a {@code <meta-data>} preference is supported is because this {@code Activity}
 * might be the very first {@code Activity} launched, which means the developer won't have
 * control over the incoming {@code Intent}.
 * <p>
 * Subclasses may override this method to directly control the initial route.
 */
@NonNull
protected String getInitialRoute() {
    if (getIntent().hasExtra(EXTRA_INITIAL_ROUTE)) {
        return getIntent().getStringExtra(EXTRA_INITIAL_ROUTE);
    }

    try {
        ActivityInfo activityInfo = getPackageManager().getActivityInfo(getComponentName(),
                PackageManager.GET_META_DATA | PackageManager.GET_ACTIVITIES);
        Bundle metadata = activityInfo.metaData;
        String desiredInitialRoute = metadata != null ? metadata.getString(INITIAL_ROUTE_META_DATA_KEY) : null;
        return desiredInitialRoute != null ? desiredInitialRoute : DEFAULT_INITIAL_ROUTE;
    } catch (PackageManager.NameNotFoundException e) {
        return DEFAULT_INITIAL_ROUTE;
    }
}

From source file:com.zegoggles.smssync.PrefStore.java

static String getVersion(Context context, boolean code) {
    android.content.pm.PackageInfo pInfo;
    try {/*from  w  w w.j a v a2 s  .  com*/
        pInfo = context.getPackageManager().getPackageInfo(SmsSync.class.getPackage().getName(),
                PackageManager.GET_META_DATA);
        return "" + (code ? pInfo.versionCode : pInfo.versionName);
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "error", e);
        return null;
    }
}

From source file:com.gm.goldencity.util.Utils.java

/**
 * Get all applications of karina in device
 *
 * @param context Application context/*w ww .  j  a v  a2  s  .c  o  m*/
 * @return
 */
public static String getKarinaPackages(Context context) {
    final PackageManager pm = context.getPackageManager();
    // get a list of installed apps.
    List<PackageInfo> packages = pm.getInstalledPackages(PackageManager.GET_META_DATA);
    // .getInstalledApplications(PackageManager.GET_META_DATA);

    String result = "";

    for (PackageInfo packageInfo : packages) {
        if (packageInfo.packageName.contains("karina")) {
            if (TextUtils.isEmpty(result))
                result = packageInfo.packageName + "(" + packageInfo.versionCode + ")";
            else
                result += ", " + packageInfo.packageName + "(" + packageInfo.versionCode + ")";
        }
    }
    return result;
}

From source file:com.zegoggles.smssync.PrefStore.java

@TargetApi(8)
static boolean isInstalledOnSDCard(Context context) {
    android.content.pm.PackageInfo pInfo;
    try {/*from   ww  w .  j a  va2 s  . co  m*/
        pInfo = context.getPackageManager().getPackageInfo(SmsSync.class.getPackage().getName(),
                PackageManager.GET_META_DATA);

        return (pInfo.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "error", e);
        return false;
    }
}