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.battlelancer.seriesguide.extensions.ExtensionManager.java

/**
 * Queries the {@link android.content.pm.PackageManager} for any installed {@link
 * com.battlelancer.seriesguide.api.SeriesGuideExtension} extensions. Their info is extracted
 * into {@link com.battlelancer.seriesguide.extensions.ExtensionManager.Extension} objects.
 *//*from  w  w  w. j  a  v a  2  s .c om*/
public List<Extension> queryAllAvailableExtensions() {
    Intent queryIntent = new Intent(SeriesGuideExtension.ACTION_SERIESGUIDE_EXTENSION);
    PackageManager pm = mContext.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentServices(queryIntent, PackageManager.GET_META_DATA);

    List<Extension> extensions = new ArrayList<>();
    for (ResolveInfo info : resolveInfos) {
        Extension extension = new Extension();
        // get label, icon and component name
        extension.label = info.loadLabel(pm).toString();
        extension.icon = info.loadIcon(pm);
        extension.componentName = new ComponentName(info.serviceInfo.packageName, info.serviceInfo.name);
        // get description
        Context packageContext;
        try {
            packageContext = mContext.createPackageContext(extension.componentName.getPackageName(), 0);
            Resources packageRes = packageContext.getResources();
            extension.description = packageRes.getString(info.serviceInfo.descriptionRes);
        } catch (SecurityException | PackageManager.NameNotFoundException | Resources.NotFoundException e) {
            Timber.e(e, "Reading description for extension " + extension.componentName + " failed");
            extension.description = "";
        }
        // get (optional) settings activity
        Bundle metaData = info.serviceInfo.metaData;
        if (metaData != null) {
            String settingsActivity = metaData.getString("settingsActivity");
            if (!TextUtils.isEmpty(settingsActivity)) {
                extension.settingsActivity = ComponentName
                        .unflattenFromString(info.serviceInfo.packageName + "/" + settingsActivity);
            }
        }

        Timber.d("queryAllAvailableExtensions: found extension " + extension.label + " "
                + extension.componentName);
        extensions.add(extension);
    }

    return extensions;
}

From source file:com.cocosw.framework.core.Base.java

@SuppressWarnings("deprecation")
@Override// w w w. j ava2 s . c o m
protected void onCreate(final Bundle savedInstanceState) {
    try {
        super.onCreate(savedInstanceState);
    } catch (Exception e) {
        //workround for V7 appcompact
    }
    LifecycleDispatcher.get().onActivityCreated(this, savedInstanceState);
    q = q == null ? new CocoQuery(this) : q;
    setContentView(layoutId());
    tintManager = new SystemBarTintManager(this);

    ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setDisplayHomeAsUpEnabled(true);
    }

    // enable status bar tint
    tintManager.setStatusBarTintEnabled(true);
    // enable navigation bar tint
    tintManager.setNavigationBarTintEnabled(true);
    if (UIUtils.hasKitKat()) {
        TypedValue typedValue = new TypedValue();
        try {
            getTheme().resolveAttribute(
                    getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA).theme,
                    typedValue, true);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        int[] attribute = new int[] { R.attr.colorPrimary, R.attr.colorPrimaryDark, R.attr.navigationBarColor,
                R.attr.statusBarColor };
        TypedArray array = this.obtainStyledAttributes(typedValue.resourceId, attribute);

        int colorPrimary = array.getResourceId(0, R.color.black);
        int colorPrimaryDark = array.getResourceId(1, -1);
        int navigationBarColor = array.getResourceId(2, -1);
        int statusBarColor = array.getResourceId(3, -1);

        colorPrimaryDark = colorPrimaryDark < 0 ? colorPrimary : colorPrimaryDark;
        navigationBarColor = navigationBarColor < 0 ? colorPrimaryDark : navigationBarColor;
        statusBarColor = statusBarColor < 0 ? colorPrimaryDark : statusBarColor;

        tintManager.setStatusBarTintResource(statusBarColor);
        tintManager.setNavigationBarTintResource(navigationBarColor);
    }

    ButterKnife.inject(this);
    // use Retained Fragment to handle runtime changes
    if (hasRetainData()) {
        FragmentManager fm = getSupportFragmentManager();
        retainedFragment = (RetainedFragment) fm.findFragmentByTag(TAG_RETAINED_STATE_FRAGMENT);

        // create the fragment and data the first time
        if (retainedFragment == null) {
            // add the fragment
            retainedFragment = new RetainedFragment();
            fm.beginTransaction().add(retainedFragment, TAG_RETAINED_STATE_FRAGMENT).commit();
        }
    }
    try {
        init(savedInstanceState);
    } catch (final RuntimeException e) {
        ExceptionManager.error(e, this);
        return;
    } catch (final Exception e) {
        ExceptionManager.error(e, this);
        finish();
        return;
    }
    onStartLoading();
    getSupportLoaderManager().initLoader(this.hashCode(), getIntent().getExtras(), this);
}

From source file:com.pranavpandey.smallapp.permission.PermissionDangerous.java

private void buildPermissionsDialog(final ArrayList<String> permissions, final boolean isRequest) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    View view = getLayoutInflater().inflate(R.layout.sas_dialog_permission, new LinearLayout(this), false);
    TextView message = (TextView) view.findViewById(R.id.permission_message);
    ViewGroup frame = (ViewGroup) view.findViewById(R.id.permission_frame);

    final ArrayList<String> permissionGroups = new ArrayList<String>();
    for (String permission : permissions) {
        try {/*from w w w  .  j a  va2 s  .  c  o m*/
            PermissionInfo permInfo = getPackageManager().getPermissionInfo(permission,
                    PackageManager.GET_META_DATA);
            if (!permissionGroups.contains(permInfo.group)) {
                permissionGroups.add(permInfo.group);
            }
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    for (String permissionGroup : permissionGroups) {
        try {
            PermissionGroupInfo permGroupInfo = getPackageManager().getPermissionGroupInfo(permissionGroup,
                    PackageManager.GET_META_DATA);
            frame.addView(new PermissionItem(this, permGroupInfo.loadIcon(getPackageManager()),
                    permGroupInfo.loadLabel(getPackageManager()).toString(),
                    permGroupInfo.loadDescription(getPackageManager()).toString()));
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (isRequest) {
        message.setText(R.string.sas_perm_request_desc);
    } else {
        message.setText(String.format(getString(R.string.sas_format_next_line),
                getString(R.string.sas_perm_request_desc), getString(R.string.sas_perm_request_info)));
    }

    try {
        alertDialogBuilder.setIcon(
                DynamicTheme.createDialogIcon(this, getPackageManager().getApplicationIcon(getPackageName())));
    } catch (Exception e) {
        e.printStackTrace();
    }
    alertDialogBuilder.setTitle(getApplicationInfo().loadLabel(getPackageManager()).toString())
            .setPositiveButton(isRequest ? R.string.sas_perm_request : R.string.sas_perm_continue,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            if (isRequest) {
                                requestPermissions(permissions.toArray(new String[permissions.size()]));
                            } else {
                                openPermissionSettings(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            }
                        }
                    })
            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    finishPermissionsChecker();
                }
            }).setCancelable(false);

    final AlertDialog dialog = alertDialogBuilder.create();
    dialog.setView(view, 0, SmallUtils.getDialogTopPadding(this), 0, 0);

    showPermissionDialog(dialog);
}

From source file:ch.gianulli.trelloapi.TrelloAPI.java

/**
 * @param context Current context (e.g. activity)
 * @throws IllegalArgumentException if the application key and secret are not in a {@code
 *                                  <meta-data>} tag inside the {@code <application>} tag in
 *                                  the app's manifest.
 *//* www  . j  a va2s . com*/
public TrelloAPI(Context context) {
    mContext = context;
    mPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    mRequestQueue = Volley.newRequestQueue(context);

    // Get application key from <meta-data> tag in manifest
    try {
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;

        if (!bundle.containsKey(META_DATA_APP_KEY)) {
            throw new IllegalArgumentException(
                    "Application key could not be found. Have you" + " put it in your application manifest?");
        }
        if (!bundle.containsKey(META_DATA_APP_SECRET)) {
            throw new IllegalArgumentException("Application secret could not be found. Have "
                    + "you put it in your application manifest?");
        }

        mAppKey = bundle.getString(META_DATA_APP_KEY);
        mAppSecret = bundle.getString(META_DATA_APP_SECRET);
    } catch (PackageManager.NameNotFoundException e) {
        throw new IllegalArgumentException("Application key and secret could not be found. "
                + "Have you put them in your application manifest?");
    }
}

From source file:net.hockeyapp.android.internal.CheckUpdateTask.java

protected int getVersionCode() {
    try {/*from  w ww . ja v  a 2s  .  com*/
        return activity.getPackageManager().getPackageInfo(activity.getPackageName(),
                PackageManager.GET_META_DATA).versionCode;
    } catch (NameNotFoundException e) {
        return 0;
    }
}

From source file:com.harshad.linconnectclient.ApplicationSettingsActivity.java

private void setupSimplePreferencesScreen() {
    addPreferencesFromResource(R.xml.pref_application);

    applicationCategory = (PreferenceCategory) findPreference("header_application");

    // Listen for check/uncheck all tap
    findPreference("pref_all").setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override// w  ww. j  a v  a 2s .  c om
        public boolean onPreferenceChange(Preference arg0, Object arg1) {
            for (int i = 0; i < applicationCategory.getPreferenceCount(); i++) {
                // Uncheck or check all items
                ((CheckBoxPreference) (applicationCategory.getPreference(i))).setChecked((Boolean) arg1);
            }
            return true;
        }
    });

    class ApplicationTask extends AsyncTask<String, Void, List<ApplicationInfo>> {
        private PackageManager packageManager;

        @Override
        protected void onPreExecute() {
            progressDialog = ProgressDialog.show(ApplicationSettingsActivity.this, null, "Loading...", true);
        }

        @Override
        protected List<ApplicationInfo> doInBackground(String... notif) {

            packageManager = getApplicationContext().getPackageManager();

            // Comparator used to sort applications by name
            class CustomComparator implements Comparator<ApplicationInfo> {
                @Override
                public int compare(ApplicationInfo arg0, ApplicationInfo arg1) {
                    return arg0.loadLabel(packageManager).toString()
                            .compareTo(arg1.loadLabel(packageManager).toString());
                }
            }

            // Get installed applications
            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            List<ApplicationInfo> appList = getApplicationContext().getPackageManager()
                    .getInstalledApplications(PackageManager.GET_META_DATA);

            // Sort by application name
            Collections.sort(appList, new CustomComparator());

            return appList;
        }

        @Override
        protected void onPostExecute(List<ApplicationInfo> result) {
            // Add each application to screen
            for (ApplicationInfo appInfo : result) {
                CheckBoxPreference c = new CheckBoxPreference(ApplicationSettingsActivity.this);
                c.setTitle(appInfo.loadLabel(packageManager).toString());
                c.setSummary(appInfo.packageName);
                c.setIcon(appInfo.loadIcon(packageManager));
                c.setKey(appInfo.packageName);
                c.setChecked(true);

                c.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference arg0, Object arg1) {
                        // On tap, show an enabled/disabled notification on the desktop
                        Object[] notif = new Object[3];

                        if (arg1.toString().equals("true")) {
                            notif[0] = arg0.getTitle().toString() + " notifications enabled";
                            notif[1] = "via LinConnect";
                            notif[2] = arg0.getIcon();
                        } else {
                            notif[0] = arg0.getTitle().toString() + " notifications disabled";
                            notif[1] = "via LinConnect";
                            notif[2] = arg0.getIcon();
                        }

                        new TestTask().execute(notif);

                        return true;
                    }

                });

                applicationCategory.addPreference(c);
            }
            progressDialog.dismiss();
        }
    }

    new ApplicationTask().execute();

}

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

/**
 * Start the sharing activity/*  w w  w .ja v  a 2  s  .c o m*/
 *
 * @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(Activity activity, ResolveInfo info, int requestCode,
        int permissionRequestCode) {
    String authority;
    String facebookId = null;
    try {
        ApplicationInfo applicationInfo = activity.getPackageManager()
                .getApplicationInfo(activity.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(activity, authority, info, permissionRequestCode);
    if (intent != null)
        manager.onShare(activity, intent, requestCode);
    return intent;
}

From source file:com.samsung.spen.SpenPlugin.java

private void init() {
    if (isStatic == null || pluginMetadata == null) {
        mActivity = cordova.getActivity();
        String mPackageName = mActivity.getPackageName();
        PackageManager pm = mActivity.getPackageManager();
        try {/*www.j  av a  2s .c o  m*/
            ApplicationInfo ai = pm.getApplicationInfo(mPackageName, PackageManager.GET_META_DATA);
            if (ai.metaData != null) {
                pluginMetadata = ai.metaData.getBoolean(META_DATA);
            } else {
                pluginMetadata = false;
            }
        } catch (NameNotFoundException e) {
            pluginMetadata = false;
        }

        isStatic = false;
        int resId = mActivity.getResources().getIdentifier("spen_static", "bool", mActivity.getPackageName());
        try {
            if (resId != 0) {
                isStatic = mActivity.getResources().getBoolean(resId);
            }
        } catch (Resources.NotFoundException re) {
            isStatic = false;
        }
        if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) {
            Log.d(TAG, "Static is " + isStatic);
        }
    }
}

From source file:com.github.czy1121.update.app.utils.UpdateUtil.java

public static int getVersionCode(Context context) {
    try {/*from   w  w w.j  a v  a 2  s .  c  om*/
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        return info.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        return 0;
    }
}

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

/**
 * Start the sharing activity/*from  www  . j  a  va 2s . c  o m*/
 *
 * @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(Activity activity, ResolveInfo info, int requestCode,
        int permissionRequestCode) {
    String authority;
    String facebookId = null;
    try {
        ApplicationInfo applicationInfo = activity.getPackageManager()
                .getApplicationInfo(activity.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(activity, authority, info, permissionRequestCode);
    if (intent != null)
        manager.onShare(activity, intent, requestCode);
    return intent;
}