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:org.jboss.aerogear.android.sync.SyncService.java

@Override
public void onCreate() {
    try {//w w  w .  j  a  v  a2  s  .c  o  m
        super.onCreate();

        ComponentName myService = new ComponentName(this, this.getClass());
        Bundle data = getPackageManager().getServiceInfo(myService, PackageManager.GET_META_DATA).metaData;

        if (data.getString(SERVER_HOST) == null) {
            throw new IllegalStateException(SERVER_HOST + " may not be null");
        }

        if (data.getString(SERVER_PATH) == null) {
            throw new IllegalStateException(SERVER_PATH + " may not be null");
        }

        if (data.getInt(SERVER_PORT, -1) == -1) {
            throw new IllegalStateException(SERVER_PORT + " may not be null");
        }

        JsonPatchClientSynchronizer synchronizer = new JsonPatchClientSynchronizer();
        ClientInMemoryDataStore<JsonNode, JsonPatchEdit> dataStore = new ClientInMemoryDataStore<JsonNode, JsonPatchEdit>();
        ClientSyncEngine<JsonNode, JsonPatchEdit> clientSyncEngine = new ClientSyncEngine<JsonNode, JsonPatchEdit>(
                synchronizer, dataStore, new DefaultPatchObservable<JsonNode>());

        syncClient = NettySyncClient.<JsonNode, JsonPatchEdit>forHost(data.getString(SERVER_HOST))
                .port(data.getInt(SERVER_PORT)).path(data.getString(SERVER_PATH)).syncEngine(clientSyncEngine)
                .build();

        Log.i(SyncService.class.getName(), "onCreated");
    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.getMessage(), ex);
        throw new IllegalStateException(ex);
    }
}

From source file:org.birthdayadapter.ui.BaseActivity.java

public boolean isPackageInstalled(String targetPackage) {
    PackageManager pm = getPackageManager();
    try {//from  ww w  .j  a v  a 2 s  . com
        PackageInfo info = pm.getPackageInfo(targetPackage, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
    return true;
}

From source file:com.dm.material.dashboard.candybar.helpers.DrawableHelper.java

@Nullable
public static Bitmap getHighQualityIcon(@NonNull Context context, String packageName) {
    try {//from ww w.j a  v a  2s  . c  o m
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo info = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA);

        Resources resources = packageManager.getResourcesForApplication(packageName);
        int density = DisplayMetrics.DENSITY_XXHIGH;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            density = DisplayMetrics.DENSITY_XXXHIGH;
        }

        Drawable drawable = ResourcesCompat.getDrawableForDensity(resources, info.icon, density, null);
        if (drawable != null)
            return ((BitmapDrawable) drawable).getBitmap();
    } catch (Exception | OutOfMemoryError e) {
        LogUtil.e(Log.getStackTraceString(e));
    }
    return null;
}

From source file:org.chromium.chrome.browser.media.remote.RemoteMediaPlayerController.java

/**
 * Create the mediaRouteControllers/*from  w w  w . jav  a  2 s . c  o  m*/
 * @param context - the current Android Context
 */
public void createMediaRouteControllers(Context context) {
    // We only need to do this once
    if (!mMediaRouteControllers.isEmpty())
        return;
    try {
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        String classNameString = bundle.getString(REMOTE_MEDIA_PLAYERS_KEY);

        if (classNameString != null) {
            String[] classNames = classNameString.split(",");
            for (String className : classNames) {
                Log.d(TAG, "Adding remote media route controller %s", className.trim());
                Class<?> mediaRouteControllerClass = Class.forName(className.trim());
                Object mediaRouteController = mediaRouteControllerClass.newInstance();
                assert mediaRouteController instanceof MediaRouteController;
                mMediaRouteControllers.add((MediaRouteController) mediaRouteController);
            }
        }
    } catch (NameNotFoundException | ClassNotFoundException | SecurityException | InstantiationException
            | IllegalAccessException | IllegalArgumentException e) {
        // Should never happen, implies corrupt AndroidManifest
        Log.e(TAG, "Couldn't instatiate MediaRouteControllers", e);
        assert false;
    }
}

From source file:com.apptentive.android.sdk.model.Configuration.java

public boolean isMessageCenterEnabled(Context context) {
    try {//from  w w w  .  j  a  va 2  s . c  o  m
        if (!isNull(KEY_MESSAGE_CENTER_ENABLED)) {
            return getBoolean(KEY_MESSAGE_CENTER_ENABLED);
        }
    } catch (JSONException e) {
        // Move on.
    }

    try {
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        Bundle metaData = ai.metaData;
        return metaData.getBoolean(Constants.MANIFEST_KEY_MESSAGE_CENTER_ENABLED,
                Constants.CONFIG_DEFAULT_MESSAGE_CENTER_ENABLED);
    } catch (Exception e) {
        Log.w("Unexpected error while reading default %s manifest setting.", e,
                Constants.MANIFEST_KEY_MESSAGE_CENTER_ENABLED);
    }

    return Constants.CONFIG_DEFAULT_MESSAGE_CENTER_ENABLED;
}

From source file:net.sf.xfd.provider.PublicProvider.java

private static @Nullable Intent authActivityIntent(Context c) {
    if (authActivity == null) {
        synchronized (PublicProvider.class) {
            if (authActivity == null) {
                final PackageManager pm = c.getPackageManager();

                final String packageName = c.getPackageName();

                try {
                    final PackageInfo pi = pm.getPackageInfo(packageName,
                            PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);

                    for (ActivityInfo activity : pi.activities) {
                        final Bundle metadata = activity.metaData;

                        if (metadata != null) {
                            boolean isSuitable = metadata.getBoolean(META_IS_PERMISSION_DELEGATE);

                            if (isSuitable) {
                                authActivity = new Intent(ACTION_PERMISSION_REQUEST)
                                        .setComponent(createRelative(packageName, activity.name))
                                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                break;
                            }//from ww w  . j  av a  2  s . com
                        }
                    }
                } catch (Exception e) {
                    return null;
                }
            }
        }
    }

    return authActivity;
}

From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java

@Override
Object getEntries(Context context) {
    PackageManager pm = context.getPackageManager();
    int requestedPackageInfoFlags = type | PackageManager.GET_DISABLED_COMPONENTS
            | (requireMetaDataSubstring != null ? PackageManager.GET_META_DATA : 0);

    boolean workAroundSmallBinderBuffer = false;
    List<PackageInfo> allPackages = null;
    try {//ww w  .  j  a v  a2 s  .  c o m
        allPackages = pm.getInstalledPackages(requestedPackageInfoFlags);
    } catch (Exception e) {
        Log.w(TAG, "Loading all apps at once failed, retrying separately", e);
    }

    if (allPackages == null || allPackages.isEmpty()) {
        workAroundSmallBinderBuffer = true;
        allPackages = pm.getInstalledPackages(0);
    }

    ArrayList<Category> selectedApps = new ArrayList<Category>();

    for (PackageInfo pack : allPackages) {
        // Filter out non-applications
        if (pack.applicationInfo == null) {
            continue;
        }

        // System app filter
        if ((((pack.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? APP_TYPE_SYSTEM : APP_TYPE_USER)
                & appType) == 0) {
            continue;
        }

        // Load component information separately if they were to big to send them all at once
        if (workAroundSmallBinderBuffer) {
            try {
                pack = pm.getPackageInfo(pack.packageName, requestedPackageInfoFlags);
            } catch (PackageManager.NameNotFoundException e) {
                Log.w(TAG, "getPackageInfo() thrown NameNotFoundException for " + pack.packageName, e);
                continue;
            }
        }

        // Scan components
        ArrayList<Component> selectedComponents = new ArrayList<Component>();

        if ((type & PackageManager.GET_ACTIVITIES) != 0) {
            scanComponents(pm, pack.activities, selectedComponents);
        }
        if ((type & PackageManager.GET_RECEIVERS) != 0) {
            scanComponents(pm, pack.receivers, selectedComponents);
        }
        if ((type & PackageManager.GET_SERVICES) != 0) {
            scanComponents(pm, pack.services, selectedComponents);
        }
        if ((type & PackageManager.GET_PROVIDERS) != 0) {
            scanComponents(pm, pack.providers, selectedComponents);
        }

        // Check if we filtered out all components and skip whole app if so
        if (selectedComponents.isEmpty()) {
            continue;
        }

        // Build and add app descriptor
        Category app = new Category();
        app.title = String.valueOf(pack.applicationInfo.loadLabel(pm));
        app.subtitle = pack.packageName;
        app.components = selectedComponents.toArray(new Component[selectedComponents.size()]);
        selectedApps.add(app);

        // Allow cancelling task
        if (Thread.interrupted()) {
            return null;
        }
    }
    return selectedApps.toArray(new Category[selectedApps.size()]);
}

From source file:android.support.v7.app.ActionBarActivityDelegate.java

protected final String getUiOptionsFromMetadata() {
    try {//w  w w  . j av a2s.co m
        PackageManager pm = mActivity.getPackageManager();
        ActivityInfo info = pm.getActivityInfo(mActivity.getComponentName(), PackageManager.GET_META_DATA);

        String uiOptions = null;
        if (info.metaData != null) {
            uiOptions = info.metaData.getString(METADATA_UI_OPTIONS);
        }
        return uiOptions;
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "getUiOptionsFromMetadata: Activity '" + mActivity.getClass().getSimpleName()
                + "' not in manifest");
        return null;
    }
}

From source file:com.nifcloud.mbaas.ncmbfcmplugin.NCMBFirebaseMessagingService.java

public NotificationCompat.Builder notificationSettings(Bundle pushData) {
    //AndroidManifest??
    ApplicationInfo appInfo = null;//  ww  w  . j av a  2 s  .  co  m
    Class startClass = null;
    String applicationName = null;
    String activityName = null;
    String packageName = null;
    int channelIcon = 0;
    try {
        appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        applicationName = getPackageManager()
                .getApplicationLabel(getPackageManager().getApplicationInfo(getPackageName(), 0)).toString();
        activityName = appInfo.packageName + ".UnityPlayerNativeActivity";
        packageName = appInfo.packageName;
    } catch (PackageManager.NameNotFoundException e) {
        throw new IllegalArgumentException(e);
    }

    Log.d("Unity", "activityName: " + activityName + "|  packageName:" + packageName);

    //Note FCM
    //????????
    Intent intent = new Intent(this, com.nifcloud.mbaas.ncmbfcmplugin.UnityPlayerActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtras(pushData);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, new Random().nextInt(), intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    //pushData??
    String message = "";
    String title = "";
    if (pushData.getString("title") != null) {
        title = pushData.getString("title");
    } else {
        //title????????
        title = applicationName;
    }
    if (pushData.getString("message") != null) {
        message = pushData.getString("message");
    }

    //SmallIconmanifests???????
    int userSmallIcon = appInfo.metaData.getInt(SMALL_ICON_KEY);
    int icon;
    if (userSmallIcon != 0) {
        //manifests??????
        icon = userSmallIcon;
    } else {
        //?????
        icon = appInfo.icon;
    }
    //SmallIcon
    int smallIconColor = appInfo.metaData.getInt(SMALL_ICON_COLOR_KEY);

    //Notification?
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,
            com.nifcloud.mbaas.ncmbfcmplugin.NCMBNotificationUtils.getDefaultChannel()).setSmallIcon(icon)//?
                    .setColor(smallIconColor)//?
                    .setContentTitle(title).setContentText(message).setAutoCancel(true)//????
                    .setSound(defaultSoundUri)//?
                    .setContentIntent(pendingIntent);//????Activity
    return notificationBuilder;
}

From source file:com.apptentive.android.sdk.util.Util.java

public static boolean getPackageMetaDataBoolean(Context context, String key) {
    try {/*www.  ja  v  a 2 s  .  com*/
        return context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA).metaData.getBoolean(key, false);
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}