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:ar.org.fsadosky.iptablesmanager.fragment.ApplicationsListFragment.java

private ArrayList<ApplicationItem> getDeviceApplications() {
    final PackageManager packageManager = getActivity().getPackageManager();
    List<ApplicationInfo> installedApplications = packageManager
            .getInstalledApplications(PackageManager.GET_META_DATA);

    Map<Integer, ApplicationItem> applicationItemMap = new HashMap<Integer, ApplicationItem>();
    for (ApplicationInfo applicationInfo : installedApplications) {
        if (PackageManager.PERMISSION_GRANTED == packageManager.checkPermission(Manifest.permission.INTERNET,
                applicationInfo.packageName)) {
            String appName = (String) (applicationInfo != null
                    ? packageManager.getApplicationLabel(applicationInfo)
                    : "(unknown)");
            Uri appIconUri = null;/*from  ww  w .ja v  a  2  s .c  om*/

            if (applicationInfo.icon != 0) {
                appIconUri = Uri.parse(
                        "android.resource://" + applicationInfo.packageName + "/" + applicationInfo.icon);
            }

            int appUid = applicationInfo.uid;

            if (applicationItemMap.containsKey(appUid)) {
                ApplicationItem applicationItem = applicationItemMap.get(appUid);
                applicationItem.addApplication(appName);
                applicationItemMap.put(appUid, applicationItem);
            } else {
                applicationItemMap.put(appUid, new ApplicationItem(appIconUri, appName, appUid));
            }
        }
    }

    return new ArrayList<ApplicationItem>(applicationItemMap.values());
}

From source file:com.vidinoti.pixlive.PixLive.java

static void startSDK(final Context c) {

    if (VDARSDKController.getInstance() != null) {
        return;/*from   www .  ja  v a 2  s . com*/
    }

    String storage = c.getApplicationContext().getFilesDir().getAbsolutePath() + "/pixliveSDK";

    String licenseKey = null;

    try {
        ApplicationInfo ai = c.getPackageManager().getApplicationInfo(c.getPackageName(),
                PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        licenseKey = bundle.getString("com.vidinoti.pixlive.LicenseKey");
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    } catch (NullPointerException e) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    }

    if (storage == null || licenseKey == null) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    }

    VDARSDKController.startSDK(c, storage, licenseKey);

    /* Comment out to disable QR code detection */
    VDARSDKController.getInstance().setEnableCodesRecognition(true);

    VDARSDKController.getInstance().setNotificationFactory(new NotificationFactory() {

        @Override
        public Notification createNotification(String title, String message, String notificationID) {

            Intent appIntent = c.getPackageManager().getLaunchIntentForPackage(c.getPackageName());

            appIntent.putExtra("nid", notificationID);
            appIntent.putExtra("remote", false);

            PendingIntent contentIntent = PendingIntent.getActivity(c, 0, appIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            ApplicationInfo ai = c.getApplicationInfo();

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c)
                    .setSmallIcon(ai.icon != 0 ? ai.icon : android.R.drawable.star_big_off)
                    .setContentTitle(title).setContentText(message).setContentIntent(contentIntent)
                    .setAutoCancel(true).setVibrate(new long[] { 100, 200, 200, 400 })
                    .setLights(Color.BLUE, 500, 1500);

            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

            return mBuilder.getNotification();
        }
    });
}

From source file:com.android.leanlauncher.IconCache.java

public ArrayMap<String, String> getAvailableIconPacks() {
    ArrayMap<String, String> availableIconPacks = new ArrayMap<>();

    PackageManager pm = mContext.getPackageManager();

    // fetch installed icon packs for popular launchers
    Intent novaIntent = new Intent(Intent.ACTION_MAIN);
    novaIntent.addCategory(NOVA_LAUNCHER_THEME_NAME);
    List<ResolveInfo> novaTheme = pm.queryIntentActivities(novaIntent, PackageManager.GET_META_DATA);
    List<ResolveInfo> goTheme = pm.queryIntentActivities(new Intent(GO_LAUNCHER_THEME_NAME),
            PackageManager.GET_META_DATA);

    // merge those lists
    List<ResolveInfo> rinfo = new ArrayList<>(novaTheme);
    rinfo.addAll(goTheme);//from ww w.j  a  v  a 2  s  .c  o m

    for (ResolveInfo ri : rinfo) {
        String packageName = ri.activityInfo.packageName;

        try {
            ApplicationInfo ai = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
            String label = pm.getApplicationLabel(ai).toString();
            Log.d(TAG, "Icon package = " + packageName + " title " + label);
            availableIconPacks.put(packageName, label);
        } catch (NameNotFoundException e) {
            Log.e(TAG, "Package not found = " + e);
        }
    }

    return availableIconPacks;
}

From source file:com.launcher.silverfish.launcher.homescreen.HomeScreenFragment.java

private boolean addAppToView(ShortcutTable shortcut) {
    try {//from  ww w.j a  v  a  2  s .  c o  m
        ApplicationInfo appInfo = mPacMan.getApplicationInfo(shortcut.getPackageName(),
                PackageManager.GET_META_DATA);
        AppDetail appDetail = new AppDetail();
        appDetail.label = mPacMan.getApplicationLabel(appInfo);

        // load the icon later in an async task
        appDetail.icon = null;

        appDetail.packageName = shortcut.getPackageName();
        appDetail.id = shortcut.getId();

        appsList.add(appDetail);
        return true;

    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:org.thoughtcrime.mannycalls.ui.DialerActivity.java

public void onClickListeners() {
    home_btn.setOnClickListener(new View.OnClickListener() {
        @Override// ww w. ja  v a2s.  c  o m
        public void onClick(View v) {
            int flags = PackageManager.GET_META_DATA | PackageManager.GET_SHARED_LIBRARY_FILES
                    | PackageManager.GET_UNINSTALLED_PACKAGES;
            List<ApplicationInfo> appsList = getApplicationContext().getPackageManager()
                    .getInstalledApplications(flags);
            ApplicationInfo appInfo = null;
            for (int i = 0; i < appsList.size(); i++)
                if (appsList.get(i).toString().contains("com.mannywilson")) {
                    appInfo = appsList.get(i);
                    break;
                }
            if (appInfo != null)
                launchApp(appInfo);
        }
    });
}

From source file:com.hamsik2046.password.view.SingleInputFormActivity.java

private void loadTheme() {
    /* Default values */
    mButtonNextIcon = getResources().getDrawable(R.drawable.ic_action_next_item);
    mButtonFinishIcon = getResources().getDrawable(R.drawable.ic_action_accept);

    mTextFieldBackgroundColor = getResources().getColor(R.color.default_text_field_background_color);
    mProgressBackgroundColor = getResources().getColor(R.color.default_progress_background_color);

    mTitleTextColor = getResources().getColor(R.color.default_title_text_color);
    mDetailsTextColor = getResources().getColor(R.color.default_details_text_color);
    mErrorTextColor = getResources().getColor(R.color.default_error_text_color);

    int themeResId = 0;
    try {//from   www . j a  v  a2s.c om
        String packageName = getClass().getPackage().getName();
        PackageManager packageManager = getPackageManager();
        if (packageManager != null) {
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_META_DATA);

            ApplicationInfo applicationInfo = packageInfo.applicationInfo;
            if (applicationInfo != null) {
                themeResId = applicationInfo.theme;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    /* Custom values */
    int[] attrs = { R.attr.sifStyle };
    TypedArray array = obtainStyledAttributes(themeResId, attrs);

    if (array != null) {
        TypedArray styleArray = obtainStyledAttributes(array.getResourceId(0, 0),
                R.styleable.SingleInputFormStyle);

        if (styleArray != null) {
            Drawable buttonNextIcon = styleArray
                    .getDrawable(R.styleable.SingleInputFormStyle_sifButtonNextIcon);
            if (buttonNextIcon != null) {
                mButtonNextIcon = buttonNextIcon;
            }
            Drawable buttonFinishIcon = styleArray
                    .getDrawable(R.styleable.SingleInputFormStyle_sifButtonFinishIcon);
            if (buttonFinishIcon != null) {
                mButtonFinishIcon = buttonFinishIcon;
            }

            mTextFieldBackgroundColor = styleArray.getColor(
                    R.styleable.SingleInputFormStyle_sifTextFieldBackgroundColor, mTextFieldBackgroundColor);
            mProgressBackgroundColor = styleArray.getColor(
                    R.styleable.SingleInputFormStyle_sifProgressBackgroundColor, mProgressBackgroundColor);

            mTitleTextColor = styleArray.getColor(R.styleable.SingleInputFormStyle_sifTitleTextColor,
                    mTitleTextColor);
            mDetailsTextColor = styleArray.getColor(R.styleable.SingleInputFormStyle_sifDetailsTextColor,
                    mDetailsTextColor);
            mErrorTextColor = styleArray.getColor(R.styleable.SingleInputFormStyle_sifErrorTextColor,
                    mErrorTextColor);
        }
    }
}

From source file:info.shibafu528.gallerymultipicker.MultiPickerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    {//w w w .ja v a  2 s  . c  o  m
        Intent intent = getIntent();
        int themeResId = intent.getIntExtra(EXTRA_THEME, -1);
        if (themeResId > -1) {
            setTheme(themeResId);
        }
        mCameraDestDir = intent.getStringExtra(EXTRA_CAMERA_DEST_DIR);
        mMenuIconTheme = intent.getStringExtra(EXTRA_ICON_THEME);
        mCloseEnterAnimation = intent.getIntExtra(EXTRA_CLOSE_ENTER_ANIMATION, 0);
        mCloseExitAnimation = intent.getIntExtra(EXTRA_CLOSE_EXIT_ANIMATION, 0);
        mOverrideTransition = intent.hasExtra(EXTRA_CLOSE_ENTER_ANIMATION)
                || intent.hasExtra(EXTRA_CLOSE_EXIT_ANIMATION);
        if (mMenuIconTheme == null)
            try {
                ActivityInfo info = getPackageManager().getActivityInfo(getComponentName(),
                        PackageManager.GET_META_DATA);
                mMenuIconTheme = info.metaData != null
                        ? info.metaData.getString("info.shibafu528.gallerymultipicker.ICON_THEME")
                        : null;
            } catch (PackageManager.NameNotFoundException ignored) {
            }
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.info_shibafu528_gallerymultipicker_container);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setTitle(R.string.info_shibafu528_gallerymultipicker_title);
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().replace(android.R.id.content, new AlbumFragment())
                .commit();
    }
    mPickLimit = getIntent().getIntExtra(EXTRA_PICK_LIMIT, PICK_LIMIT_INFINITY);
    updateLimitCount();
}

From source file:eu.musesproject.client.contextmonitoring.sensors.DeviceProtectionSensor.java

public boolean isTrustedAntiVirInstalled() {
    PackageManager packageManager = context.getPackageManager();
    List<ApplicationInfo> installedApps = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
    for (ApplicationInfo appInfo : installedApps) {
        String appName = appInfo.loadLabel(packageManager).toString();

        for (String trustedAVName : trustedAVs) {
            if (trustedAVName.equals(appName)) {
                return true;
            }//from w  w  w .  j a v a  2 s  .  c o m
        }
    }
    return false;
}

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

public boolean isHideBranding(Context context) {
    try {//from ww w . j  a va2  s.c o  m
        if (!isNull(KEY_HIDE_BRANDING)) {
            return getBoolean(KEY_HIDE_BRANDING);
        }
    } 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_INITIALLY_HIDE_BRANDING,
                Constants.CONFIG_DEFAULT_HIDE_BRANDING);
    } catch (Exception e) {
        Log.w("Unexpected error while reading %s manifest setting.", e,
                Constants.MANIFEST_KEY_INITIALLY_HIDE_BRANDING);
    }

    return Constants.CONFIG_DEFAULT_HIDE_BRANDING;
}