Example usage for android.content.pm ResolveInfo loadLabel

List of usage examples for android.content.pm ResolveInfo loadLabel

Introduction

In this page you can find the example usage for android.content.pm ResolveInfo loadLabel.

Prototype

public CharSequence loadLabel(PackageManager pm) 

Source Link

Document

Retrieve the current textual label associated with this resolution.

Usage

From source file:com.android.launcher3.allapps.AllAppsGridAdapter.java

public void setSearchController(AllAppsSearchBarController searchController) {
    mSearchController = searchController;

    // Resolve the market app handling additional searches
    PackageManager pm = mLauncher.getPackageManager();
    ResolveInfo marketInfo = pm.resolveActivity(mSearchController.createMarketSearchIntent(""),
            PackageManager.MATCH_DEFAULT_ONLY);
    if (marketInfo != null) {
        mMarketAppName = marketInfo.loadLabel(pm).toString();
    }//from   www . j a  v  a  2  s.co m
}

From source file:com.anysoftkeyboard.addons.AddOnsFactory.java

private List<E> getExternalAddOns() {
    if (!mReadExternalPacksToo)//this will disable external packs (API careful stage)
        return Collections.emptyList();

    final PackageManager packageManager = mContext.getPackageManager();
    final List<ResolveInfo> broadcastReceivers = packageManager
            .queryBroadcastReceivers(new Intent(mReceiverInterface), PackageManager.GET_META_DATA);

    final List<E> externalAddOns = new ArrayList<>();

    for (final ResolveInfo receiver : broadcastReceivers) {
        if (receiver.activityInfo == null) {
            Logger.e(mTag, "BroadcastReceiver has null ActivityInfo. Receiver's label is "
                    + receiver.loadLabel(packageManager));
            Logger.e(mTag, "Is the external keyboard a service instead of BroadcastReceiver?");
            // Skip to next receiver
            continue;
        }/*w ww . ja  va2s  . c  o m*/

        if (!receiver.activityInfo.enabled || !receiver.activityInfo.applicationInfo.enabled)
            continue;

        try {
            final Context externalPackageContext = mContext
                    .createPackageContext(receiver.activityInfo.packageName, Context.CONTEXT_IGNORE_SECURITY);
            final List<E> packageAddOns = getAddOnsFromActivityInfo(externalPackageContext,
                    receiver.activityInfo);

            externalAddOns.addAll(packageAddOns);
        } catch (final NameNotFoundException e) {
            Logger.e(mTag, "Did not find package: " + receiver.activityInfo.packageName);
        }

    }

    return externalAddOns;
}

From source file:com.novemser.voicetest.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_template);

    initView();/*from ww w.  jav  a 2 s . c  o  m*/
    //test.db?
    db = openOrCreateDatabase("alarm.db", Context.MODE_PRIVATE, null);

    mAdapter = new ListMessageAdapter(this, mDatas);
    mChatView.setAdapter(mAdapter);
    packageManager = getPackageManager();

    // Context
    BaseAction.context = getApplicationContext();

    SpeechUtility.createUtility(getApplicationContext(), SpeechConstant.APPID + "=573d5744");
    //1.RecognizerDialog
    mDialog = new RecognizerDialog(this, null);
    mIat = SpeechRecognizer.createRecognizer(getApplicationContext(), null);
    //2.accent? language?
    mDialog.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
    mDialog.setParameter(SpeechConstant.ACCENT, "mandarin");

    //?UI???onResult?
    //

    //         mDialog.setParameter("asr_sch", "1");
    //         mDialog.setParameter("nlp_version", "2.0");
    //3.?
    mDialog.setListener(new RecognizerDialogListener() {
        @Override
        public void onResult(RecognizerResult recognizerResult, boolean b) {
            Log.d("VoiceResult", recognizerResult.getResultString());
            printResult(recognizerResult);
        }

        @Override
        public void onError(SpeechError speechError) {

        }
    });

    // 4.
    mStartVoiceRecord.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //dialog
            mDialog.show();
        }
    });

    // ?TTS
    initTTS();

    // 5.??
    understander = TextUnderstander.createTextUnderstander(this, null);

    // 6.???
    SharedPreferences sharedPreferences = getSharedPreferences("user", MODE_PRIVATE);

    if (!sharedPreferences.getBoolean("isContactUploaded", false)) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        ContactManager manager = ContactManager.createManager(this, contactListener);
        manager.asyncQueryAllContactsName();
        editor.putBoolean("isContactUploaded", true);
        editor.apply();
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.title_toolbar));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        toolbar.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
    }
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    new Thread(new Runnable() {
        /**
         * ?
         */
        @Override
        public void run() {
            //?
            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            resolveInfoList = packageManager.queryIntentActivities(mainIntent, 0);
            //???
            Collections.sort(resolveInfoList, new ResolveInfo.DisplayNameComparator(packageManager));
            for (ResolveInfo res : resolveInfoList) {
                String pkg = res.activityInfo.packageName;
                String cls = res.activityInfo.name;
                String name = res.loadLabel(packageManager).toString();
                Log.d("ApplicationInfo:", "Pkg:" + pkg + "   Class:" + cls + "   Name:" + name);
            }
        }
    }).start();

    // ?
    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).build();
}

From source file:com.google.android.apps.muzei.settings.ChooseSourceFragment.java

public void updateSources() {
    mSelectedSource = null;/*from w  w  w.ja v a 2  s . c o m*/
    Intent queryIntent = new Intent(ACTION_MUZEI_ART_SOURCE);
    PackageManager pm = getContext().getPackageManager();
    mSources.clear();
    List<ResolveInfo> resolveInfos = pm.queryIntentServices(queryIntent, PackageManager.GET_META_DATA);

    for (ResolveInfo ri : resolveInfos) {
        Source source = new Source();
        source.label = ri.loadLabel(pm).toString();
        source.icon = new BitmapDrawable(getResources(), generateSourceImage(ri.loadIcon(pm)));
        source.targetSdkVersion = ri.serviceInfo.applicationInfo.targetSdkVersion;
        source.componentName = new ComponentName(ri.serviceInfo.packageName, ri.serviceInfo.name);
        if (ri.serviceInfo.descriptionRes != 0) {
            try {
                Context packageContext = getContext()
                        .createPackageContext(source.componentName.getPackageName(), 0);
                Resources packageRes = packageContext.getResources();
                source.description = packageRes.getString(ri.serviceInfo.descriptionRes);
            } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
                Log.e(TAG, "Can't read package resources for source " + source.componentName);
            }
        }
        Bundle metaData = ri.serviceInfo.metaData;
        source.color = Color.WHITE;
        if (metaData != null) {
            String settingsActivity = metaData.getString("settingsActivity");
            if (!TextUtils.isEmpty(settingsActivity)) {
                source.settingsActivity = ComponentName
                        .unflattenFromString(ri.serviceInfo.packageName + "/" + settingsActivity);
            }

            String setupActivity = metaData.getString("setupActivity");
            if (!TextUtils.isEmpty(setupActivity)) {
                source.setupActivity = ComponentName
                        .unflattenFromString(ri.serviceInfo.packageName + "/" + setupActivity);
            }

            source.color = metaData.getInt("color", source.color);

            try {
                float[] hsv = new float[3];
                Color.colorToHSV(source.color, hsv);
                boolean adjust = false;
                if (hsv[2] < 0.8f) {
                    hsv[2] = 0.8f;
                    adjust = true;
                }
                if (hsv[1] > 0.4f) {
                    hsv[1] = 0.4f;
                    adjust = true;
                }
                if (adjust) {
                    source.color = Color.HSVToColor(hsv);
                }
                if (Color.alpha(source.color) != 255) {
                    source.color = Color.argb(255, Color.red(source.color), Color.green(source.color),
                            Color.blue(source.color));
                }
            } catch (IllegalArgumentException ignored) {
            }
        }

        mSources.add(source);
    }

    final String appPackage = getContext().getPackageName();
    Collections.sort(mSources, new Comparator<Source>() {
        @Override
        public int compare(Source s1, Source s2) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                boolean target1IsO = s1.targetSdkVersion >= Build.VERSION_CODES.O;
                boolean target2IsO = s2.targetSdkVersion >= Build.VERSION_CODES.O;
                if (target1IsO && !target2IsO) {
                    return 1;
                } else if (!target1IsO && target2IsO) {
                    return -1;
                }
            }
            String pn1 = s1.componentName.getPackageName();
            String pn2 = s2.componentName.getPackageName();
            if (!pn1.equals(pn2)) {
                if (appPackage.equals(pn1)) {
                    return -1;
                } else if (appPackage.equals(pn2)) {
                    return 1;
                }
            }
            return s1.label.compareTo(s2.label);
        }
    });

    redrawSources();
}

From source file:com.lite.android.launcher3.allapps.AllAppsGridAdapter.java

public AllAppsGridAdapter(Launcher launcher, AlphabeticalAppsList apps, View.OnTouchListener touchListener,
        View.OnClickListener iconClickListener, View.OnLongClickListener iconLongClickListener) {
    Resources res = launcher.getResources();
    mLauncher = launcher;//from   w  w w. j  a  va 2s. c  o  m
    mApps = apps;
    mEmptySearchMessage = res.getString(R.string.all_apps_loading_message);
    mGridSizer = new GridSpanSizer();
    mGridLayoutMgr = new AppsGridLayoutManager(launcher);
    mGridLayoutMgr.setSpanSizeLookup(mGridSizer);
    mItemDecoration = new GridItemDecoration();
    mLayoutInflater = LayoutInflater.from(launcher);
    mTouchListener = touchListener;
    mIconClickListener = iconClickListener;
    mIconLongClickListener = iconLongClickListener;
    mSectionNamesMargin = mSectionStrategy == AllAppsContainerView.SECTION_STRATEGY_GRID
            ? res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin)
            : res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin_with_sections);

    mAllAppsTextColor = mGridTheme == AllAppsContainerView.GRID_THEME_DARK
            ? res.getColor(R.color.quantum_panel_text_color_dark)
            : res.getColor(R.color.quantum_panel_text_color);

    mSectionHeaderOffset = res.getDimensionPixelSize(R.dimen.all_apps_grid_section_y_offset);

    mSectionTextPaint = new Paint();
    mSectionTextPaint.setTextSize(res.getDimensionPixelSize(R.dimen.all_apps_grid_section_text_size));
    int sectionTextColorId = mGridTheme == AllAppsContainerView.GRID_THEME_DARK
            ? R.color.all_apps_grid_section_text_color_dark
            : R.color.all_apps_grid_section_text_color;
    mSectionTextPaint.setColor(res.getColor(sectionTextColorId));
    mSectionTextPaint.setAntiAlias(true);

    mPredictedAppsDividerPaint = new Paint();
    mPredictedAppsDividerPaint.setStrokeWidth(Utilities.pxFromDp(1f, res.getDisplayMetrics()));
    mPredictedAppsDividerPaint.setColor(0x1E000000);
    mPredictedAppsDividerPaint.setAntiAlias(true);
    mPredictionBarDividerOffset = res.getDimensionPixelSize(R.dimen.all_apps_prediction_bar_divider_offset);

    // Resolve the market app handling additional searches
    PackageManager pm = launcher.getPackageManager();
    ResolveInfo marketInfo = pm.resolveActivity(createMarketSearchIntent(""),
            PackageManager.MATCH_DEFAULT_ONLY);
    if (marketInfo != null) {
        mMarketAppName = marketInfo.loadLabel(pm).toString();
    }

    mRemoteFolderManager = launcher.getRemoteFolderManager();
}

From source file:com.example.android.home.Home.java

/**
 * Loads the list of installed applications in mApplications.
 */// w w w  .  j  a v a 2  s . co m
private void loadApplications(boolean isLaunching) {
    if (isLaunching && mApplications != null) {
        return;
    }

    PackageManager manager = getPackageManager();

    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
    Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));

    if (apps != null) {
        final int count = apps.size();

        if (mApplications == null) {
            mApplications = new ArrayList<ApplicationInfo>(count);
        }
        mApplications.clear();

        for (int i = 0; i < count; i++) {
            //for (int i = 0; i < 6; i++) {            // show only 6 apps
            ApplicationInfo application = new ApplicationInfo();
            ResolveInfo info = apps.get(i);

            application.title = info.loadLabel(manager);
            application.setActivity(
                    new ComponentName(info.activityInfo.applicationInfo.packageName, info.activityInfo.name),
                    Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

            Log.v("Home APP", "package neme= " + info.activityInfo.applicationInfo.packageName);
            Log.v("Home APP", "neme= " + info.activityInfo.name);
            Log.v("Home APP", "title= " + application.title);

            application.icon = info.activityInfo.loadIcon(manager);

            // TODO
            // Replace Icons
            //if((application.title+"").equals("Calculator")) application.icon = getResources().getDrawable(R.drawable.ic_launcher_home_big);

            // Add Application
            if ((application.title + "").equals("Browser"))
                mApplications.add(application);
            if ((application.title + "").equals("Phone"))
                mApplications.add(application);
            if ((application.title + "").equals("People"))
                mApplications.add(application);
            if ((application.title + "").equals("Messaging"))
                mApplications.add(application);
            if ((application.title + "").equals("Settings"))
                mApplications.add(application);

        }

        // Took from http://hi-android.info/src/index.html
        // ********************* ADD Call Log
        ApplicationInfo application = new ApplicationInfo();
        application.title = "Call Log";
        application.icon = getResources().getDrawable(R.drawable.ic_launcher_home);
        application.setActivity(
                new ComponentName("com.android.contacts", "com.android.contacts.RecentCallsListActivity"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);
    }
}

From source file:org.mozilla.gecko.GeckoAppShell.java

static String[] getHandlersForIntent(Intent intent) {
    PackageManager pm = GeckoApp.mAppContext.getPackageManager();
    List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
    int numAttr = 4;
    String[] ret = new String[list.size() * numAttr];
    for (int i = 0; i < list.size(); i++) {
        ResolveInfo resolveInfo = list.get(i);
        ret[i * numAttr] = resolveInfo.loadLabel(pm).toString();
        if (resolveInfo.isDefault)
            ret[i * numAttr + 1] = "default";
        else//from  w  w w.  j  a  v a2  s. c  om
            ret[i * numAttr + 1] = "";
        ret[i * numAttr + 2] = resolveInfo.activityInfo.applicationInfo.packageName;
        ret[i * numAttr + 3] = resolveInfo.activityInfo.name;
    }
    return ret;
}

From source file:com.coinomi.wallet.ui.widget.ActivityChooserView.java

/**
 * Updates the buttons state.//  www.  j a v a  2  s  .  c o  m
 */
private void updateAppearance() {
    // Expand overflow button.
    if (mAdapter.getCount() > 0) {
        mExpandActivityOverflowButton.setEnabled(true);
    } else {
        mExpandActivityOverflowButton.setEnabled(false);
    }
    // Default activity button.
    final int activityCount = mAdapter.getActivityCount();
    final int historySize = mAdapter.getHistorySize();
    // http://stackoverflow.com/questions/15755465/how-to-hide-the-share-action-which-use-most-icon-near-the-share-action-provide/17290249#17290249
    if (false) {
        mDefaultActivityButton.setVisibility(VISIBLE);
        ResolveInfo activity = mAdapter.getDefaultActivity();
        PackageManager packageManager = getContext().getPackageManager();
        mDefaultActivityButtonImage.setImageDrawable(activity.loadIcon(packageManager));
        if (mDefaultActionButtonContentDescription != 0) {
            CharSequence label = activity.loadLabel(packageManager);
            String contentDescription = getContext().getString(mDefaultActionButtonContentDescription, label);
            mDefaultActivityButton.setContentDescription(contentDescription);
        }
    } else {
        mDefaultActivityButton.setVisibility(View.GONE);
    }
    // Activity chooser content.
    if (mDefaultActivityButton.getVisibility() == VISIBLE) {
        mActivityChooserContent.setBackgroundDrawable(mActivityChooserContentBackground);
    } else {
        mActivityChooserContent.setBackgroundDrawable(null);
    }
}

From source file:com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment.java

/**
 * Gets the display info.//from   ww w  .  j  a va  2  s  .com
 */
private List<DisplayInfo> getDisplayInfos() {
    List<DisplayInfo> displayInfos = new ArrayList<DisplayInfo>();
    Intent intent = ShareCompat.IntentBuilder.from(getActivity()).setType(IntentUtils.TEXT_PLAIN_TYPE)
            .getIntent();
    List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (resolveInfos != null && resolveInfos.size() > 0) {
        int size = resolveInfos.size();
        ResolveInfo firstResolveInfo = resolveInfos.get(0);
        for (int i = 1; i < size; i++) {
            ResolveInfo resolveInfo = resolveInfos.get(i);
            if (firstResolveInfo.priority != resolveInfo.priority
                    || firstResolveInfo.isDefault != resolveInfo.isDefault) {
                while (i < size) {
                    resolveInfos.remove(i);
                    size--;
                }
            }
        }
        if (size > 1) {
            ResolveInfo.DisplayNameComparator displayNameComparator = new ResolveInfo.DisplayNameComparator(
                    packageManager);
            Collections.sort(resolveInfos, displayNameComparator);
        }

        firstResolveInfo = resolveInfos.get(0);
        int start = 0;
        CharSequence firstLabel = firstResolveInfo.loadLabel(packageManager);
        for (int i = 1; i < size; i++) {
            if (firstLabel == null) {
                firstLabel = firstResolveInfo.activityInfo.packageName;
            }
            ResolveInfo resolveInfo = resolveInfos.get(i);
            CharSequence label = resolveInfo.loadLabel(packageManager);
            if (label == null) {
                label = resolveInfo.activityInfo.packageName;
            }
            if (label.equals(firstLabel)) {
                continue;
            }
            processGroup(resolveInfos, displayInfos, start, i - 1);
            firstResolveInfo = resolveInfo;
            firstLabel = label;
            start = i;
        }
        // Process last group
        processGroup(resolveInfos, displayInfos, start, size - 1);
    }
    return displayInfos;
}