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 String getName(Context context, ResolveInfo resolveInfo) {
    return String.valueOf(resolveInfo.loadLabel(context.getPackageManager()));
}

From source file:fr.simon.marquis.secretcodes.util.Utils.java

public static void print(ResolveInfo r, PackageManager pm) {
    Log.e("",/*from ww w .j a  va  2s. c om*/
            "r.labelRes=[" + r.labelRes + "], r.priority=[" + r.priority + "], r.resolvePackageName=["
                    + r.resolvePackageName + "], r.getIconResource()=[" + r.getIconResource()
                    + "], r.loadLabel(pm)=[" + r.loadLabel(pm) + "], r.preferredOrder=[" + r.preferredOrder
                    + "], r.priority=[" + r.priority + "], r.specificIndex=[" + r.specificIndex
                    + "], r.isDefault=[" + r.isDefault + "], r.activityInfo.icon=["
                    + (r.activityInfo == null ? null : r.activityInfo.icon) + "], r.activityInfo.logo=["
                    + (r.activityInfo == null ? null : r.activityInfo.logo) + "], r.activityInfo.packageName =["
                    + (r.activityInfo == null ? null : r.activityInfo.packageName) + "], r.serviceInfo.icon=["
                    + (r.serviceInfo == null ? null : r.serviceInfo.icon) + "], r.serviceInfo.logo=["
                    + (r.serviceInfo == null ? null : r.serviceInfo.logo) + "], r.serviceInfo.packageName=["
                    + (r.serviceInfo == null ? null : r.serviceInfo.packageName) + "]");
}

From source file:com.bangalore.barcamp.BCBUtils.java

public static void addNavigationActions(final BCBActivityBaseClass homeActivity) {
    homeActivity.setBehindContentView(R.layout.navigation_menu);
    int offset = 100;
    DisplayMetrics metrics = new DisplayMetrics();
    homeActivity.getWindow().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    offset = ((metrics.widthPixels * 130)) / 480;

    homeActivity.setBehindOffset(offset);
    homeActivity.setBehindScrollScale(0.5f);

    View view = homeActivity.findViewById(R.id.nav_agenda);
    view.setOnClickListener(new OnClickListener() {

        @Override//  ww w  . j a v a  2 s .com
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, ScheduleActivity.class);
            homeActivity.startActivityForResult(intent, START_SCHEDULE);

        }
    });

    view = homeActivity.findViewById(R.id.nav_about);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, AboutActivity.class);
            homeActivity.startActivityForResult(intent, START_ABOUT);
        }
    });
    view = homeActivity.findViewById(R.id.nav_internal_venue_map);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, InternalVenueMapActivity.class);
            homeActivity.startActivityForResult(intent, START_INTERNAL_VENUE);
        }
    });

    view = homeActivity.findViewById(R.id.nav_settings);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, SettingsActivity.class);
            homeActivity.startActivityForResult(intent, START_SETTINGS);
        }
    });
    view.setVisibility(View.GONE);
    view = homeActivity.findViewById(R.id.nav_share);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, ShareActivity.class);
            homeActivity.startActivityForResult(intent, START_SHARE);
        }
    });
    view = homeActivity.findViewById(R.id.nav_tweets);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, WebViewActivity.class);
            intent.putExtra(WebViewActivity.URL, "file:///android_asset/bcb11_updates.html");
            homeActivity.startActivityForResult(intent, START_BCB12_TWEETS);
        }
    });
    view = homeActivity.findViewById(R.id.nav_update);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, UpdateMessagesActivity.class);
            homeActivity.startActivityForResult(intent, START_BCB_UPDATES);
        }
    });
    view = homeActivity.findViewById(R.id.nav_venue);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            final PackageManager pm = homeActivity.getPackageManager();

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(BCB_LOCATION_MAPS_URL));
            final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0);
            for (ResolveInfo info : matches) {
                Log.e("MapPackage", info.loadLabel(pm) + " " + info.activityInfo.packageName + " "
                        + info.activityInfo.name);
                if (info.activityInfo.name.equals("com.google.android.maps.MapsActivity")) {
                    intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
                }
            }

            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            homeActivity.startActivity(intent);
        }
    });
    view = homeActivity.findViewById(R.id.nav_BCB);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://barcampbangalore.org"));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            homeActivity.startActivity(intent);
        }
    });

}

From source file:com.xlythe.engine.theme.Theme.java

/**
 * Returns a list of installed apps that are registered as themes
 *///from w  w  w . ja  v a  2 s . com
public static List<App> getApps(Context context) {
    LinkedList<App> apps = new LinkedList<App>();
    PackageManager manager = context.getPackageManager();

    Intent mainIntent = new Intent(context.getPackageName() + ".THEME", null);

    final List<ResolveInfo> infos;
    try {
        infos = manager.queryIntentActivities(mainIntent, 0);
    } catch (Exception e) {
        e.printStackTrace();
        return apps;
    }

    for (ResolveInfo info : infos) {
        App app = new App();
        apps.add(app);

        app.setName(info.loadLabel(manager).toString());
        app.setPackageName(info.activityInfo.applicationInfo.packageName);
    }

    return apps;
}

From source file:stepic.stepic.BaseMapsActivity.java

/**
 * Build the list of items to show using the intent_listview_row layout.
 *
 * @param context/*from   w ww.j  a va  2  s . c  o m*/
 * @param activitiesInfo
 * @return
 */
private static ArrayAdapter<ResolveInfo> buildAdapter(final Context context,
        final List<ResolveInfo> activitiesInfo) {
    return new ArrayAdapter<ResolveInfo>(context, R.layout.intent_listview_row, R.id.title, activitiesInfo) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            ResolveInfo res = activitiesInfo.get(position);
            ImageView image = (ImageView) view.findViewById(R.id.icon);
            image.setImageDrawable(res.loadIcon(context.getPackageManager()));
            TextView textview = (TextView) view.findViewById(R.id.title);
            textview.setText(res.loadLabel(context.getPackageManager()).toString());

            return view;
        }
    };
}

From source file:com.felkertech.n.ActivityUtils.java

public static void browsePlugins(final Activity activity) {
    //Same opening
    final PackageManager pm = activity.getPackageManager();
    final Intent plugin_addchannel = new Intent(CumulusTvPlugin.ACTION_ADD_CHANNEL);
    final List<ResolveInfo> plugins = pm.queryIntentActivities(plugin_addchannel, 0);
    ArrayList<String> plugin_names = new ArrayList<>();
    for (ResolveInfo ri : plugins) {
        plugin_names.add(ri.loadLabel(pm).toString());
    }//from  w  w  w.  j a v  a2s .c o  m
    String[] plugin_names2 = plugin_names.toArray(new String[plugin_names.size()]);

    new MaterialDialog.Builder(activity).title(R.string.installed_plugins).items(plugin_names2)
            .itemsCallback(new MaterialDialog.ListCallback() {
                @Override
                public void onSelection(MaterialDialog materialDialog, View view, int i,
                        CharSequence charSequence) {
                    // Load the given plugin with some additional info
                    ChannelDatabase cd = ChannelDatabase.getInstance(activity);
                    String s = cd.toString();
                    Intent intent = new Intent();
                    if (DEBUG) {
                        Log.d(TAG, "Try to start");
                    }
                    ResolveInfo plugin_info = plugins.get(i);
                    Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                            + plugin_info.activityInfo.name);

                    intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                            plugin_info.activityInfo.name);
                    intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EXTRA_READ_ALL);
                    intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ALL_CHANNELS, s);
                    activity.startActivity(intent);
                }
            }).positiveText(R.string.download_more_plugins)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse("http://play.google.com/store/search?q=cumulustv&c=apps"));
                    activity.startActivity(i);
                }
            }).show();
}

From source file:com.felkertech.n.ActivityUtils.java

public static void openPluginPicker(final boolean newChannel, final JsonChannel queriedChannel,
        final Activity activity) {
    final PackageManager pm = activity.getPackageManager();
    final Intent plugin_addchannel = new Intent(CumulusTvPlugin.ACTION_ADD_CHANNEL);
    final List<ResolveInfo> plugins = pm.queryIntentActivities(plugin_addchannel, 0);
    ArrayList<String> plugin_names = new ArrayList<String>();
    for (ResolveInfo ri : plugins) {
        plugin_names.add(ri.loadLabel(pm).toString());
    }//from  ww w.  j av  a 2  s . c  o m
    String[] plugin_names2 = plugin_names.toArray(new String[plugin_names.size()]);
    if (DEBUG) {
        Log.d(TAG, "Load plugins " + plugin_names.toString());
    }
    if (plugin_names.size() == 1) {
        Intent intent = new Intent();
        if (newChannel) {
            if (DEBUG) {
                Log.d(TAG, "Try to start ");
            }
            ResolveInfo plugin_info = plugins.get(0);
            if (DEBUG) {
                Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                        + plugin_info.activityInfo.name);
            }

            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                    plugin_info.activityInfo.name);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD);
        } else {
            ResolveInfo plugin_info = plugins.get(0);
            Log.d(TAG,
                    plugin_info.activityInfo.applicationInfo.packageName + " " + plugin_info.activityInfo.name);
            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                    plugin_info.activityInfo.name);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, queriedChannel.toString());
        }
        activity.startActivity(intent);
    } else {
        new MaterialDialog.Builder(activity).items(plugin_names2).title(R.string.choose_an_app)
                .content(R.string.choose_default_app).itemsCallback(new MaterialDialog.ListCallback() {
                    @Override
                    public void onSelection(MaterialDialog materialDialog, View view, int i,
                            CharSequence charSequence) {
                        Intent intent = new Intent();
                        if (newChannel) {
                            if (DEBUG) {
                                Log.d(TAG, "Try to start");
                            }
                            ResolveInfo plugin_info = plugins.get(i);
                            if (DEBUG) {
                                Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                                        + plugin_info.activityInfo.name);
                            }

                            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                                    plugin_info.activityInfo.name);

                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD);
                        } else {
                            ResolveInfo plugin_info = plugins.get(i);
                            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                                    plugin_info.activityInfo.name);
                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, queriedChannel.toString());
                        }
                        activity.startActivity(intent);
                    }
                }).show();
    }
}

From source file:com.mods.grx.settings.utils.Utils.java

public static String get_label_from_packagename_activityname(Context context, String nombre_paquete,
        String nombre_actividad) {

    String etiqueta = "-";
    Intent intent = new Intent();
    intent.setComponent(new ComponentName(nombre_paquete, nombre_actividad));

    ResolveInfo ri = context.getPackageManager().resolveActivity(intent, 0);
    if (ri != null) {
        etiqueta = ri.loadLabel(context.getPackageManager()).toString();
    } else//from   w ww. j a v  a  2  s .c om
        etiqueta = "";

    ApplicationInfo aitemp;
    String eti_app = "";
    try {
        aitemp = context.getPackageManager().getApplicationInfo(ri.activityInfo.packageName, 0);
        eti_app = context.getPackageManager().getApplicationLabel(aitemp).toString();
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (eti_app.equals(etiqueta))
        etiqueta = nombre_actividad;
    else {
        etiqueta = etiqueta;
    }
    if (etiqueta.contains("."))
        etiqueta = Utils.format_label(etiqueta);
    return etiqueta;

}

From source file:com.android.test.uibench.MainActivity.java

protected List<Map<String, Object>> getData(String prefix) {
    List<Map<String, Object>> myData = new ArrayList<>();

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

    PackageManager pm = getPackageManager();
    List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);

    if (null == list)
        return myData;

    String[] prefixPath;//from   w  w  w .  j a  v  a  2s .  c  o m
    String prefixWithSlash = prefix;

    if (prefix.equals("")) {
        prefixPath = null;
    } else {
        prefixPath = prefix.split("/");
        prefixWithSlash = prefix + "/";
    }

    int len = list.size();

    Map<String, Boolean> entries = new HashMap<>();

    for (int i = 0; i < len; i++) {
        ResolveInfo info = list.get(i);
        CharSequence labelSeq = info.loadLabel(pm);
        String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name;

        if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) {

            String[] labelPath = label.split("/");

            String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];

            if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
                addItem(myData, nextLabel,
                        activityIntent(info.activityInfo.applicationInfo.packageName, info.activityInfo.name));
            } else {
                if (entries.get(nextLabel) == null) {
                    addItem(myData, nextLabel,
                            browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
                    entries.put(nextLabel, true);
                }
            }
        }
    }

    Collections.sort(myData, sDisplayNameComparator);

    return myData;
}

From source file:com.bangalore.barcamp.activity.ShareActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.share_screen);
    mDrawerToggle = BCBFragmentUtils.setupActionBar(this, "Share");

    // BCBUtils.createActionBarOnActivity(this);
    // BCBUtils.addNavigationActions(this);
    ((EditText) findViewById(R.id.editText1)).addTextChangedListener(new TextWatcher() {

        @Override/* w w w .j a va  2 s .  co m*/
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            ((TextView) findViewById(R.id.charsLeftTextView)).setText("Chars left: " + (140 - s.length() - 7));
        }
    });
    if (getIntent().hasExtra(SHARE_STRING)) {
        ((EditText) findViewById(R.id.editText1)).setText(getIntent().getStringExtra(SHARE_STRING));
    }
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    final PackageManager pm = getPackageManager();
    final Spinner spinner = (Spinner) findViewById(R.id.shareTypeSpinner);
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0);
    String selectedItem = BCBSharedPrefUtils.getShareSettings(getApplicationContext());
    int selectedPos = -1;
    for (ResolveInfo info : matches) {
        adapter.add(info.loadLabel(pm));
        if (selectedItem.equals(info.loadLabel(pm))) {
            selectedPos = matches.indexOf(info);
        }
    }
    spinner.setAdapter(adapter);

    if (selectedPos != -1) {
        spinner.setSelected(true);
        spinner.setSelection(selectedPos);
    }
    ((TextView) findViewById(R.id.charsLeftTextView)).setText("Chars left: 140");
    ((Button) findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            int appSelectedPos = spinner.getSelectedItemPosition();
            ResolveInfo info = matches.get(appSelectedPos);
            intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);

            BCBSharedPrefUtils.setShareSettings(getApplicationContext(), (String) info.loadLabel(pm));
            intent.putExtra(Intent.EXTRA_TEXT,
                    ((EditText) findViewById(R.id.editText1)).getText().toString() + " #barcampblr");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            startActivity(intent);
            finish();

        }
    });

    BCBFragmentUtils.addNavigationActions(this);
    supportInvalidateOptionsMenu();
    Tracker t = ((BarcampBangalore) getApplication()).getTracker();

    // Set screen name.
    t.setScreenName(this.getClass().getName());

    // Send a screen view.
    t.send(new HitBuilders.AppViewBuilder().build());

}