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.todoroo.astrid.helper.SyncActionHelper.java

public void performSyncAction() {
    List<SyncV2Provider> activeV2Providers = syncService.activeProviders();
    int activeSyncs = syncActions.size() + activeV2Providers.size();

    if (activeSyncs == 0) {
        String desiredCategory = activity.getString(R.string.SyP_label);

        // Get a list of all sync plugins and bring user to the prefs pane
        // for one of them
        Intent queryIntent = new Intent(AstridApiConstants.ACTION_SETTINGS);
        PackageManager pm = activity.getPackageManager();
        List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(queryIntent, PackageManager.GET_META_DATA);
        int length = resolveInfoList.size();
        ArrayList<Intent> syncIntents = new ArrayList<Intent>();

        // Loop through a list of all packages (including plugins, addons)
        // that have a settings action: filter to sync actions
        for (int i = 0; i < length; i++) {
            ResolveInfo resolveInfo = resolveInfoList.get(i);
            Intent intent = new Intent(AstridApiConstants.ACTION_SETTINGS);
            intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);

            String category = MetadataHelper.resolveActivityCategoryName(resolveInfo, pm);

            if (GtasksPreferences.class.getName().equals(resolveInfo.activityInfo.name))
                continue;

            if (resolveInfo.activityInfo.metaData != null) {
                Bundle metadata = resolveInfo.activityInfo.metaData;
                if (!metadata.getBoolean("syncAction")) //$NON-NLS-1$
                    continue;
            }//from  w  w  w . jav a2s  .  c  o m

            if (category.equals(desiredCategory)) {
                syncIntents.add(new IntentWithLabel(intent, resolveInfo.activityInfo.loadLabel(pm).toString()));
            }
        }

        final Intent[] actions = syncIntents.toArray(new Intent[syncIntents.size()]);
        DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface click, int which) {
                fragment.startActivityForResult(actions[which], TaskListFragment.ACTIVITY_SETTINGS);
            }
        };
        if (actions.length == 1) {
            fragment.startActivityForResult(actions[0], TaskListFragment.ACTIVITY_SETTINGS);
        } else {
            showSyncOptionMenu(actions, listener);
        }

    } else {
        syncService.synchronizeActiveTasks(true, syncResultCallback);
    }
}

From source file:io.rapidpro.androidchannel.RapidPro.java

public void refreshInstalledPacks() {

    final PackageManager pm = getPackageManager();
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

    List<String> packs = new ArrayList<String>();
    for (ApplicationInfo packageInfo : packages) {
        if (packageInfo.packageName.startsWith("io.rapidpro.androidchannel")) {
            packs.add(packageInfo.packageName);
        }/*from   www  .  ja va2s  . c o m*/
    }

    LOG.d("Found " + packs.size() + " installed messaging packs");
    for (String pack : packs) {
        LOG.d("   - " + pack);
    }

    m_installedPacks = packs;
}

From source file:io.nuclei.cyto.share.ShareIntent.java

/**
 * Start the sharing activity//from www .  j a v a  2 s .c om
 *
 * @param info The activity info
 * @param requestCode The request code to receive back from the started activity
 * @param permissionRequestCode The permission request code in case we need access to external storage
 */
public Intent startActivityForResult(Fragment fragment, ResolveInfo info, int requestCode,
        int permissionRequestCode) {
    String authority;
    String facebookId = null;
    try {
        ApplicationInfo applicationInfo = fragment.getActivity().getPackageManager()
                .getApplicationInfo(fragment.getActivity().getPackageName(), PackageManager.GET_META_DATA);
        authority = applicationInfo.metaData.getString(SHARING_AUTHORITY);
        if (PackageTargetManager.FACEBOOK.equals(info.activityInfo.packageName))
            facebookId = applicationInfo.metaData.getString("com.facebook.sdk.ApplicationId");
    } catch (Exception err) {
        throw new RuntimeException(err);
    }
    if (TextUtils.isEmpty(authority))
        Log.w(TAG, MISSING_CONFIG);
    PackageTargetManager manager = mTargetListeners == null ? null
            : mTargetListeners.get(info.activityInfo.packageName);
    if (manager == null) {
        if (mDefaultTargetManager == null)
            manager = new DefaultPackageTargetManager();
        else
            manager = mDefaultTargetManager;
    }
    manager.initialize(mText, mUri, mUrl, mEmail, mSubject, mFile);
    manager.mFacebookId = facebookId;
    Intent intent = manager.onCreateIntent(fragment.getActivity(), authority, info, permissionRequestCode);
    if (intent != null)
        manager.onShare(fragment, intent, requestCode);
    return intent;
}

From source file:org.teleportr.activity.Autocompletion.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.about:
        startActivity(new Intent(this, About.class));
        break;// ww w.  j a va  2 s .  co  m

    case R.id.refresh:
        new FetchNearbyDownloads().execute("");
        break;

    case R.id.feedback:
        new AlertDialog.Builder(this).setTitle("feedback").setIcon(android.R.drawable.ic_dialog_info)
                .setPositiveButton("send logs", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        LogCollector.feedback(Autocompletion.this, "scotty@teleportr.org, flo@andlabs.de");
                    }
                }).setNeutralButton("mail scotty", new Dialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Intent.ACTION_SENDTO,
                                Uri.parse("mailto:scotty@teleportr.org, flo@andlabs.de"));
                        intent.putExtra(Intent.EXTRA_SUBJECT, "feedback " + getString(R.string.app_name));
                        try {
                            PackageInfo info = getPackageManager().getPackageInfo("org.teleportr",
                                    PackageManager.GET_META_DATA);
                            intent.putExtra(Intent.EXTRA_TEXT,
                                    "version: " + info.versionName + " (" + info.versionCode + ") \n");
                        } catch (NameNotFoundException e) {
                        }
                        startActivity(intent);
                    }
                }).show();
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:nuclei.ui.share.ShareIntent.java

/**
 * Start the sharing activity/*from  w  w w  .  jav  a2  s .  com*/
 *
 * @param info The activity info
 * @param requestCode The request code to receive back from the started activity
 * @param permissionRequestCode The permission request code in case we need access to external storage
 */
public Intent startActivityForResult(Fragment fragment, ResolveInfo info, int requestCode,
        int permissionRequestCode) {
    String authority;
    String facebookId = null;
    try {
        ApplicationInfo applicationInfo = fragment.getActivity().getPackageManager()
                .getApplicationInfo(fragment.getActivity().getPackageName(), PackageManager.GET_META_DATA);
        authority = applicationInfo.metaData.getString(SHARING_AUTHORITY);
        if (PackageTargetManager.FACEBOOK.equals(info.activityInfo.packageName))
            facebookId = applicationInfo.metaData.getString("com.facebook.sdk.ApplicationId");
    } catch (Exception err) {
        throw new RuntimeException(err);
    }
    if (TextUtils.isEmpty(authority))
        Log.w(TAG, MISSING_CONFIG);
    PackageTargetManager manager = mTargetListeners == null ? null
            : mTargetListeners.get(info.activityInfo.packageName);
    if (manager == null) {
        if (mDefaultTargetManager == null)
            manager = new DefaultPackageTargetManager();
        else
            manager = mDefaultTargetManager;
    }
    manager.initialize(mText, mUri, mUrl, mSms, mEmail, mSubject, mFile);
    manager.mFacebookId = facebookId;
    Intent intent = manager.onCreateIntent(fragment.getActivity(), authority, info, permissionRequestCode);
    if (intent != null)
        manager.onShare(fragment, intent, requestCode);
    return intent;
}

From source file:com.jungle.base.utils.MiscUtils.java

public static int getIntMetaData(String metaKey) {
    Context context = BaseApplication.getAppContext();
    try {//from w  w  w.  ja  v a  2  s . c  o  m
        ApplicationInfo info = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        if (info.metaData != null && info.metaData.containsKey(metaKey)) {
            return info.metaData.getInt(metaKey);
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    return 0;
}

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

public boolean isMessageCenterEmailRequired(Context context) {
    try {//from w w w . j  a va 2 s .  co  m
        JSONObject messageCenter = getMessageCenter();
        if (messageCenter != null) {
            if (!messageCenter.isNull(KEY_MESSAGE_CENTER_EMAIL_REQUIRED)) {
                return messageCenter.getBoolean(KEY_MESSAGE_CENTER_EMAIL_REQUIRED);
            }
        }
    } 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_EMAIL_REQUIRED,
                Constants.CONFIG_DEFAULT_MESSAGE_CENTER_EMAIL_REQUIRED);
    } catch (Exception e) {
        Log.w("Unexpected error while reading %s manifest setting.", e, Constants.MANIFEST_KEY_EMAIL_REQUIRED);
    }

    return Constants.CONFIG_DEFAULT_MESSAGE_CENTER_EMAIL_REQUIRED;
}

From source file:com.onesignal.OneSignal.java

private static void init(OneSignal.Builder inBuilder) {
    mInitBuilder = inBuilder;/*w  w w . j  a  v a 2  s  .  c  om*/

    Context context = mInitBuilder.mContext;
    mInitBuilder.mContext = null; // Clear to prevent leaks.

    try {
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        OneSignal.init(context, bundle.getString("onesignal_google_project_number").substring(4),
                bundle.getString("onesignal_app_id"), mInitBuilder.mNotificationOpenedHandler);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.lhtechnologies.DoorApp.AuthenticatorService.java

private int getVersion() {
    int version = -1;
    try {//  ww  w .  jav a  2  s . c  om
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
        version = pInfo.versionCode;
    } catch (PackageManager.NameNotFoundException e1) {
        Log.e(this.getClass().getSimpleName(), "Name not found", e1);
    }
    return version;
}

From source file:com.ibm.bluelist.LoginActivity.java

private Bundle getMergedOptions() {
    // Read activity metadata from AndroidManifest.xml
    ActivityInfo activityInfo = null;//from  www . ja v  a2 s .c  o m
    try {
        activityInfo = getPackageManager().getActivityInfo(this.getComponentName(),
                PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {

        Log.w(LOG_TAG, e.getMessage());
    }

    Bundle mergedOptions = new Bundle();
    if (activityInfo != null && activityInfo.metaData != null) {
        mergedOptions.putAll(activityInfo.metaData);
    }
    if (getIntent().getExtras() != null) {
        mergedOptions.putAll(getIntent().getExtras());
    }

    return mergedOptions;
}