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:Main.java

public static void openMailChooser(Context context, String text, String[] mails, String subject) {
    Intent mailIntent = new Intent();
    mailIntent.setAction(Intent.ACTION_SEND);
    mailIntent.putExtra(Intent.EXTRA_TEXT, text);
    mailIntent.putExtra(Intent.EXTRA_EMAIL, mails);
    mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    mailIntent.setType(INTENT_TYPE_MSG);

    PackageManager pm = context.getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType(INTENT_TYPE_TEXT);

    Intent openInChooser = Intent.createChooser(mailIntent, "");

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (ResolveInfo ri : resInfo) {
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains(PACKAGE_EMAIL)) {
            mailIntent.setPackage(packageName);
        } else if (packageName.contains(PACKAGE_MMS) || packageName.contains(PACKAGE_GMAIL)) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType(INTENT_TYPE_TEXT);
            if (packageName.contains(PACKAGE_MMS)) {
                intent.putExtra("subject", subject);
                intent.putExtra("sms_body", text);
                intent.putExtra("address", mails[0]);
                intent.setType(INTENT_TYPE_MSG);
            } else if (packageName.contains(PACKAGE_GMAIL)) {
                intent.putExtra(Intent.EXTRA_TEXT, text);
                intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                intent.putExtra(Intent.EXTRA_EMAIL, mails);
                intent.setType(INTENT_TYPE_MSG);
            }//  w  ww  . j a  va 2s .c o  m

            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }

    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    context.startActivity(openInChooser);
}

From source file:com.example.android.supportv4.accessibility.AccessibilityManagerSupportActivity.java

/**
 * Updates the content of a TextView with description of the enabled
 * accessibility services./* w ww  . j  a va2s . c  o m*/
 */
private void updateAccessibilityStateView() {
    // The API for getting the enabled accessibility services based on feedback
    // type was added in ICS. Therefore to be backwards compatible we use the
    // APIs in the support library. Note that if the platform API version is lower
    // and the called API is not available an empty list of services is returned.
    List<AccessibilityServiceInfo> enabledServices = AccessibilityManagerCompat
            .getEnabledAccessibilityServiceList(mAccessibilityManager,
                    AccessibilityServiceInfo.FEEDBACK_SPOKEN);
    if (!enabledServices.isEmpty()) {
        StringBuilder builder = new StringBuilder();
        final int enabledServiceCount = enabledServices.size();
        for (int i = 0; i < enabledServiceCount; i++) {
            AccessibilityServiceInfo service = enabledServices.get(i);
            // Some new APIs were added in ICS for getting more information about
            // an accessibility service. Again accessed them via the support library.
            ResolveInfo resolveInfo = AccessibilityServiceInfoCompat.getResolveInfo(service);
            String serviceDescription = getString(R.string.accessibility_manager_enabled_service,
                    resolveInfo.loadLabel(getPackageManager()),
                    AccessibilityServiceInfoCompat.feedbackTypeToString(service.feedbackType),
                    AccessibilityServiceInfoCompat.getDescription(service),
                    AccessibilityServiceInfoCompat.getSettingsActivityName(service));
            builder.append(serviceDescription);
        }
        mAccessibilityStateView.setText(builder);
    } else {
        // Either no services or the platform API version is not high enough.
        mAccessibilityStateView.setText(getString(R.string.accessibility_manager_no_enabled_services));
    }
}

From source file:br.com.bioscada.apps.biotracks.fragments.ChooseActivityDialogFragment.java

/**
 * Processes a group of items with the same label.
 * //from  w  w  w  .j a  v a  2 s  . c  o  m
 * @param resolveInfos list of resolve infos
 * @param displayInfos list of display infos
 * @param start start index
 * @param end end index
 */
private void processGroup(List<ResolveInfo> resolveInfos, List<DisplayInfo> displayInfos, int start, int end) {
    ResolveInfo startResolveInfo = resolveInfos.get(start);
    CharSequence primaryLabel = startResolveInfo.loadLabel(packageManager);
    Drawable icon = startResolveInfo.loadIcon(packageManager);

    int num = end - start + 1;
    if (num == 1) {
        // Only one, set the secondary label to null
        displayInfos.add(new DisplayInfo(startResolveInfo, primaryLabel, null, icon));
    } else {
        // Decide package name or application name for the secondary label
        boolean usePackageName = false;
        CharSequence appName = startResolveInfo.activityInfo.applicationInfo.loadLabel(packageManager);
        if (appName == null) {
            usePackageName = true;
        } else {
            // Use HashSet to track duplicates
            HashSet<CharSequence> duplicates = new HashSet<CharSequence>();
            duplicates.add(appName);
            for (int i = start + 1; i <= end; i++) {
                ResolveInfo resolveInfo = resolveInfos.get(i);
                CharSequence name = resolveInfo.activityInfo.applicationInfo.loadLabel(packageManager);
                if ((name == null) || (duplicates.contains(name))) {
                    usePackageName = true;
                    break;
                } else {
                    duplicates.add(name);
                }
            }
            // Clear HashSet for later use
            duplicates.clear();
        }
        for (int i = start; i <= end; i++) {
            ResolveInfo resolveInfo = resolveInfos.get(i);
            CharSequence secondaryLabel = usePackageName ? resolveInfo.activityInfo.packageName
                    : resolveInfo.activityInfo.applicationInfo.loadLabel(packageManager);
            displayInfos.add(new DisplayInfo(resolveInfo, primaryLabel, secondaryLabel, icon));
        }
    }
}

From source file:com.marstemp.widgets.DynamicShareActionProvider.java

@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    subMenu.clear();/* www  .ja  v  a 2 s .c  o  m*/
    if (pm != null && list != null && list.size() > 0) {
        for (int i = 0; i < list.size(); i++) {
            ResolveInfo resolveInfo = list.get(i);
            OnMenuItemClickUpdateIntentListener itemListener = new OnMenuItemClickUpdateIntentListener();
            itemListener.setPosition(i);
            MenuItem item = subMenu.add(resolveInfo.loadLabel(pm)).setIcon(resolveInfo.loadIcon(pm))
                    .setOnMenuItemClickListener(itemListener);
        }
    } else {
        String msg;
        if (shareIntent == null || shareIntent.getType() == null || shareIntent.getType().equals("")) {
            msg = context.getString(R.string.no_share_type);
        } else if (list == null || list.size() <= 0) {
            String formatMsg = context.getString(R.string.no_app_to_share);
            msg = String.format(formatMsg, shareIntent.getType());
        } else {
            msg = context.getString(R.string.error_occurred);
        }

        Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
    }
}

From source file:com.actionbarsherlock.widget.ShareActionProvider.java

/**
 * {@inheritDoc}// w w w  .  j  a v  a2  s  .  com
 */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();

    ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName);
    PackageManager packageManager = mContext.getPackageManager();

    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);

    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager))
                .setOnMenuItemClickListener(mOnMenuItemClickListener);
    }

    if (collapsedActivityCount < expandedActivityCount) {
        // Add a sub-menu for showing all activities as a list item.
        SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount,
                mContext.getString(R.string.abs__activity_chooser_view_see_all));
        for (int i = 0; i < expandedActivityCount; i++) {
            ResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager))
                    .setIcon(activity.loadIcon(packageManager))
                    .setOnMenuItemClickListener(mOnMenuItemClickListener);
        }
    }
}

From source file:com.appmanager.parimal.activity.MainActivity.java

private void loadApps() {

    manager = this.getPackageManager();
    apps = new ArrayList<AppDetail>();

    Intent i = new Intent(Intent.ACTION_MAIN, null);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    AppEntryDBHelper mDbHelper = new AppEntryDBHelper(getApplicationContext());
    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    List<ResolveInfo> availableActivities = manager.queryIntentActivities(i, 0);
    for (ResolveInfo ri : availableActivities) {
        if (!ri.activityInfo.packageName.matches("com.appmanager.parimal")) {
            AppDetail app = new AppDetail();
            app.setLabel(ri.loadLabel(manager));
            app.setName(ri.activityInfo.packageName);
            app.setIcon(ri.activityInfo.loadIcon(manager));
            apps.add(app);//from  ww w. j  av a  2 s .c  o  m
            ContentValues values = new ContentValues();
            values.put(AppsReaderContract.AppEntry.COLUMN_APP_NAME, ri.loadLabel(manager).toString());
            values.put(AppsReaderContract.AppEntry.COLUMN_APP_PACKAGE, ri.activityInfo.packageName);
            values.put(AppsReaderContract.AppEntry.COLUMN_APP_CATEGORY, "Uncategorized");
            values.put(AppsReaderContract.AppEntry.COLUMN_APP_PIN, "0000");
            values.put(AppsReaderContract.AppEntry.COLUMN_APP_PIN_USE, "false");
            values.put(AppsReaderContract.AppEntry.COLUMN_APP_USAGE, "0");

            long newRowId;
            newRowId = db.insert(AppsReaderContract.AppEntry.TABLE_NAME, null, values);
        }

    }
    db.close();
}

From source file:com.example.FilteredShareActionProvider.java

/**
 * {@inheritDoc}/*from  www  .  ja v  a 2s  .c o  m*/
 */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();

    FilteredActivityChooserModel dataModel = FilteredActivityChooserModel.get(mContext, mShareHistoryFileName);
    PackageManager packageManager = mContext.getPackageManager();

    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);

    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager))
                .setOnMenuItemClickListener(mOnMenuItemClickListener);
    }

    if (collapsedActivityCount < expandedActivityCount) {
        // Add a sub-menu for showing all activities as a list item.
        SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount,
                mContext.getString(R.string.abc_activity_chooser_view_see_all));
        for (int i = 0; i < expandedActivityCount; i++) {
            ResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager))
                    .setIcon(activity.loadIcon(packageManager))
                    .setOnMenuItemClickListener(mOnMenuItemClickListener);
        }
    }
}

From source file:android.support.v7.widget.ShareActionProvider.java

/**
 * {@inheritDoc}//from  ww w  . ja v  a 2  s  .c  o m
 */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();

    ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName);
    PackageManager packageManager = mContext.getPackageManager();

    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);

    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager))
                .setOnMenuItemClickListener(mOnMenuItemClickListener);
    }

    if (collapsedActivityCount < expandedActivityCount) {
        // Add a sub-menu for showing all activities as a list item.
        SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount,
                mContext.getString(R.string.abc_activity_chooser_view_see_all));
        for (int i = 0; i < expandedActivityCount; i++) {
            ResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager))
                    .setIcon(activity.loadIcon(packageManager))
                    .setOnMenuItemClickListener(mOnMenuItemClickListener);
        }
    }
}

From source file:fr.rolandl.smartshareactionprovider.SmartShareActionProvider.java

/**
 * {@inheritDoc}//from  w  w  w  . ja  v  a 2  s .com
 */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();

    SmartActivityChooserModel dataModel = SmartActivityChooserModel.get(mContext, mShareHistoryFileName);
    PackageManager packageManager = mContext.getPackageManager();

    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);

    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager))
                .setOnMenuItemClickListener(mOnMenuItemClickListener);
    }

    if (collapsedActivityCount < expandedActivityCount) {
        // Add a sub-menu for showing all activities as a list item.
        SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount,
                mContext.getString(R.string.abc_activity_chooser_view_see_all));
        for (int i = 0; i < expandedActivityCount; i++) {
            ResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager))
                    .setIcon(activity.loadIcon(packageManager))
                    .setOnMenuItemClickListener(mOnMenuItemClickListener);
        }
    }
}

From source file:com.launcher.silverfish.launcher.appdrawer.AppDrawerTabFragment.java

/**
 * Loads apps from the database//from   w  w w.j  a v a2 s. co m
 */
private void loadApps() {

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

    switch ((int) tabId) {
    case 1:
        // Tab 1 is a special tab and includes all except for the ones in other tabs
        // Retrieve all installed apps on the device
        List<ResolveInfo> availableActivities = mPacMan.queryIntentActivities(i, 0);

        // And only add those that are not in the database
        for (int j = 0; j < availableActivities.size(); j++) {
            ResolveInfo ri = availableActivities.get(j);

            if (sqlHelper.containsApp(ri.activityInfo.packageName))
                continue;

            AppDetail app = new AppDetail();
            app.label = ri.loadLabel(mPacMan);
            app.packageName = ri.activityInfo.packageName;

            // Load the icon later in an async task.
            app.icon = null;

            appsList.add(app);
        }
        break;
    default:
        // All other tabs just query the apps from the database
        List<AppTable> apps = sqlHelper.getAppsForTab(tabId);
        for (AppTable app : apps) {

            boolean success = addAppToList(app.getPackageName());
            // If the app could not be added then it was probably uninstalled,
            // so we have to remove it from the database
            if (!success) {
                Log.d("DB", "Removing app " + app.getPackageName() + " from db");
                sqlHelper.removeAppFromTab(app.getPackageName(), this.tabId);
            }
        }

        // show the empty category notice if this tab is empty
        if (apps.size() == 0) {
            showEmptyCategoryNotice();
        }
    }
}