Example usage for android.content.pm PackageManager queryIntentActivities

List of usage examples for android.content.pm PackageManager queryIntentActivities

Introduction

In this page you can find the example usage for android.content.pm PackageManager queryIntentActivities.

Prototype

public abstract List<ResolveInfo> queryIntentActivities(Intent intent, @ResolveInfoFlags int flags);

Source Link

Document

Retrieve all activities that can be performed for the given intent.

Usage

From source file:com.vuze.android.remote.fragment.FilesFragment.java

@SuppressWarnings("unused")
protected boolean reallyStreamFile(Map<?, ?> selectedFile) {
    final String contentURL = getContentURL(selectedFile);
    if (contentURL != null && contentURL.length() > 0) {
        Uri uri = Uri.parse(contentURL);

        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        String name = MapUtils.getMapString(selectedFile, "name", "video");
        intent.putExtra("title", name);

        String extension = MimeTypeMap.getFileExtensionFromUrl(contentURL).toLowerCase(Locale.US);
        String mimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (mimetype != null && tryLaunchWithMimeFirst) {
            intent.setType(mimetype);/*from ww w  .j  ava2s . c  om*/
        }
        Class<?> fallBackIntentClass = VideoViewer.class;
        if (mimetype != null && mimetype.startsWith("image")) {
            fallBackIntentClass = ImageViewer.class;
        }

        final PackageManager packageManager = getActivity().getPackageManager();
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (AndroidUtils.DEBUG) {
            Log.d(TAG, "num intents " + list.size());
            for (ResolveInfo info : list) {
                ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info);
                Log.d(TAG, info.toString() + "/"
                        + (componentInfo == null ? "null" : (componentInfo.name + "/" + componentInfo)));
            }
        }
        if (list.size() == 0) {
            // Intent will launch, but show message to the user:
            // "Opening web browser links is not supported"
            intent.setClass(getActivity(), fallBackIntentClass);
        }
        if (list.size() == 1) {
            ResolveInfo info = list.get(0);
            ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info);
            if (componentInfo != null && componentInfo.name != null) {
                if ("com.amazon.unifiedshare.actionchooser.BuellerShareActivity".equals(componentInfo.name)
                        || componentInfo.name.startsWith("com.google.android.tv.frameworkpackagestubs.Stubs")) {
                    intent.setClass(getActivity(), fallBackIntentClass);
                }
            }
        }

        try {
            startActivity(intent);
            if (AndroidUtils.DEBUG) {
                Log.d(TAG, "Started " + uri + " MIME: " + intent.getType());
            }
        } catch (java.lang.SecurityException es) {
            if (AndroidUtils.DEBUG) {
                Log.d(TAG, "ERROR launching. " + es.toString());
            }

            if (mimetype != null) {
                try {
                    Intent intent2 = new Intent(Intent.ACTION_VIEW, uri);
                    intent2.putExtra("title", name);
                    if (!tryLaunchWithMimeFirst) {
                        intent2.setType(mimetype);
                    }

                    list = packageManager.queryIntentActivities(intent2, PackageManager.MATCH_DEFAULT_ONLY);
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG, "num intents " + list.size());
                        for (ResolveInfo info : list) {
                            ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info);
                            Log.d(TAG, info.toString() + "/" + (componentInfo == null ? "null"
                                    : (componentInfo.name + "/" + componentInfo)));
                        }
                    }

                    startActivity(intent2);
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG,
                                "Started with" + (intent2.getType() == null ? " no" : " ") + " mime: " + uri);
                    }
                    return true;
                } catch (Throwable ex2) {
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG, "no intent for view. " + ex2.toString());
                    }
                }
            }

            Toast.makeText(getActivity().getApplicationContext(),
                    getActivity().getResources().getString(R.string.intent_security_fail), Toast.LENGTH_LONG)
                    .show();
        } catch (android.content.ActivityNotFoundException ex) {
            if (AndroidUtils.DEBUG) {
                Log.d(TAG, "no intent for view. " + ex.toString());
            }

            if (mimetype != null) {
                try {
                    Intent intent2 = new Intent(Intent.ACTION_VIEW, uri);
                    intent2.putExtra("title", name);
                    if (!tryLaunchWithMimeFirst) {
                        intent2.setType(mimetype);
                    }
                    startActivity(intent2);
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG, "Started (no mime set) " + uri);
                    }
                    return true;
                } catch (android.content.ActivityNotFoundException ex2) {
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG, "no intent for view. " + ex2.toString());
                    }
                }
            }

            Toast.makeText(getActivity().getApplicationContext(),
                    getActivity().getResources().getString(R.string.no_intent), Toast.LENGTH_SHORT).show();
        }
        return true;
    }

    return true;
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppObj.java

@Override
public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) {
    PackageManager pm = context.getPackageManager();
    Drawable icon = null;//from   w ww.j a  v a 2s. c  o  m
    String appName;
    if (obj.getJson() != null && obj.getJson().has(ANDROID_PACKAGE_NAME)) {
        appName = obj.getJson().optString(ANDROID_PACKAGE_NAME);
    } else {
        appName = "Unknown";
    }
    if (!(obj instanceof DbObj)) {
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
        String text = "Preparing application " + appName + "...";
        // TODO: Show Market icon or app icon.
        TextView valueTV = new TextView(context);
        valueTV.setText(text);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
        return;
    }

    DbObj dbParentObj = (DbObj) obj;
    boolean rendered = false;

    Intent launch = getLaunchIntent(context, dbParentObj);
    List<ResolveInfo> infos = pm.queryIntentActivities(launch, 0);
    if (infos.size() > 0) {
        ResolveInfo info = infos.get(0);
        if (info.activityInfo.labelRes != 0) {
            appName = info.activityInfo.loadLabel(pm).toString();
            icon = info.loadIcon(pm);
        } else {
            appName = info.activityInfo.name;
        }
    } else {
        appName = obj.getJson().optString(ANDROID_PACKAGE_NAME);
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
    }
    // TODO: Safer reference to containing view
    if (icon != null) {
        View parentView = (View) frame.getParent().getParent();
        ImageView avatar = (ImageView) parentView.findViewById(R.id.icon);
        avatar.setImageDrawable(icon);

        TextView label = (TextView) parentView.findViewById(R.id.name_text);
        label.setText(appName);
    }

    // TODO: obj.getLatestChild().render();
    String selection = getRenderableClause();
    String[] selectionArgs = null;
    Cursor cursor = dbParentObj.getSubfeed().query(selection, selectionArgs);
    if (cursor.moveToFirst()) {
        DbObj dbObj = App.instance().getMusubi().objForCursor(cursor);
        DbObjects.getFeedRenderer(dbObj.getType()).render(context, frame, dbObj, allowInteractions);
        rendered = true;
    }

    if (!rendered) {
        String text;
        if (icon != null) {
            ImageView iv = new ImageView(context);
            iv.setImageDrawable(icon);
            iv.setAdjustViewBounds(true);
            iv.setMaxWidth(60);
            iv.setMaxHeight(60);
            iv.setLayoutParams(CommonLayouts.WRAPPED);
            frame.addView(iv);
            text = appName;
        } else {
            text = "New application: " + appName + ".";
        }
        // TODO: Show Market icon or app icon.
        TextView valueTV = new TextView(context);
        valueTV.setText(text);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
    }
}

From source file:com.todoroo.astrid.activity.TaskListFragment.java

protected void addMenuItems(Menu menu, Activity activity) {
    boolean isTablet = AstridPreferences.useTabletLayout(activity);
    TaskListActivity tla = null;/*from  w w  w  .jav  a 2 s .  c om*/
    if (activity instanceof TaskListActivity) {
        tla = (TaskListActivity) activity;
        tla.getMainMenuPopover().clear();
    }
    // --- sync
    if (tla == null
            || tla.getTaskEditFragment() == null && Preferences.getBoolean(R.string.p_show_menu_sync, true))
        addSyncRefreshMenuItem(menu, isTablet ? ThemeService.FLAG_INVERT : 0);

    // --- sort
    if (allowResorting() && Preferences.getBoolean(R.string.p_show_menu_sort, true)) {
        addMenuItem(menu, R.string.TLA_menu_sort, ThemeService.getDrawable(R.drawable.icn_menu_sort_by_size,
                isTablet ? ThemeService.FLAG_FORCE_DARK : 0), MENU_SORT_ID, false);
    }

    // --- new filter
    if (Preferences.getBoolean(R.string.p_use_filters, true))
        addMenuItem(menu, R.string.FLA_new_filter, ThemeService.getDrawable(R.drawable.icn_menu_filters,
                isTablet ? ThemeService.FLAG_FORCE_DARK : 0), MENU_NEW_FILTER_ID, false);

    // ask about plug-ins
    Intent queryIntent = new Intent(AstridApiConstants.ACTION_TASK_LIST_MENU);

    PackageManager pm = getActivity().getPackageManager();
    List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(queryIntent, 0);
    int length = resolveInfoList.size();
    for (int i = 0; i < length; i++) {
        ResolveInfo resolveInfo = resolveInfoList.get(i);
        Intent intent = new Intent(AstridApiConstants.ACTION_TASK_LIST_MENU);
        intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
        addMenuItem(menu, resolveInfo.loadLabel(pm), resolveInfo.loadIcon(pm), intent, MENU_ADDON_INTENT_ID);
    }
}

From source file:com.aimfire.main.MainActivity.java

/**
 * share only to certain apps. code based on "http://stackoverflow.com/questions/
 * 9730243/how-to-filter-specific-apps-for-action-send-intent-and-set-a-different-
 * text-for/18980872#18980872"// ww  w . j  a v a2  s. c  o  m
 *
 * "copy link" inspired by http://cketti.de/2016/06/15/share-url-to-clipboard/
 *
 * in general, "deep linking" is supported by the apps below. Facebook, Wechat,
 * Telegram are exceptions. click on the link would bring users to the landing
 * page.
 *
 * Facebook doesn't take our EXTRA_TEXT so user will have to "copy link" first
 * then paste the link
 */
private void inviteFriend() {
    mFirebaseAnalytics.logEvent(MainConsts.FIREBASE_CUSTOM_EVENT_INVITE, null);

    Resources resources = getResources();

    /*
     * construct link
     */
    String appLink = resources.getString(R.string.app_store_link);

    /*
     * message subject and text
     */
    String emailSubject, emailText, twitterText;

    emailSubject = resources.getString(R.string.emailSubjectInviteFriend);
    emailText = resources.getString(R.string.emailBodyInviteFriend) + appLink;
    twitterText = resources.getString(R.string.emailBodyInviteFriend) + appLink + ", "
            + resources.getString(R.string.app_hashtag);

    Intent emailIntent = new Intent();
    emailIntent.setAction(Intent.ACTION_SEND);
    // Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
    //emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_native)));
    emailIntent.setType("message/rfc822");

    PackageManager pm = getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");

    Intent openInChooser = Intent.createChooser(emailIntent, resources.getString(R.string.share_chooser_text));

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (int i = 0; i < resInfo.size(); i++) {
        // Extract the label, append it, and repackage it in a LabeledIntent
        ResolveInfo ri = resInfo.get(i);
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains("android.email")) {
            emailIntent.setPackage(packageName);
        } else if (packageName.contains("twitter") || packageName.contains("facebook")
                || packageName.contains("whatsapp") || packageName.contains("tencent.mm") || //wechat
                packageName.contains("line") || packageName.contains("skype") || packageName.contains("viber")
                || packageName.contains("kik") || packageName.contains("sgiggle") || //tango
                packageName.contains("kakao") || packageName.contains("telegram")
                || packageName.contains("nimbuzz") || packageName.contains("hike")
                || packageName.contains("imoim") || packageName.contains("bbm")
                || packageName.contains("threema") || packageName.contains("mms")
                || packageName.contains("android.apps.messaging") || //google messenger
                packageName.contains("android.talk") || //google hangouts
                packageName.contains("android.gm")) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            if (packageName.contains("twitter")) {
                intent.putExtra(Intent.EXTRA_TEXT, twitterText);
            } else if (packageName.contains("facebook")) {
                /*
                 * the warning below is wrong! at least on GS5, Facebook client does take
                 * our text, however it seems it takes only the first hyperlink in the
                 * text.
                 *
                 * Warning: Facebook IGNORES our text. They say "These fields are intended
                 * for users to express themselves. Pre-filling these fields erodes the
                 * authenticity of the user voice."
                 * One workaround is to use the Facebook SDK to post, but that doesn't
                 * allow the user to choose how they want to share. We can also make a
                 * custom landing page, and the link will show the <meta content ="...">
                 * text from that page with our link in Facebook.
                 */
                intent.putExtra(Intent.EXTRA_TEXT, appLink);
            } else if (packageName.contains("tencent.mm")) //wechat
            {
                /*
                 * wechat appears to do this similar to Facebook
                 */
                intent.putExtra(Intent.EXTRA_TEXT, appLink);
            } else if (packageName.contains("android.gm")) {
                // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
                intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
                //intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail)));
                intent.setType("message/rfc822");
            } else if (packageName.contains("android.apps.docs")) {
                /*
                 * google drive - no reason to send link to it
                 */
                continue;
            } else {
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
            }

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

    /*
     *  create "Copy Link To Clipboard" Intent
     */
    Intent clipboardIntent = new Intent(this, CopyToClipboardActivity.class);
    clipboardIntent.setData(Uri.parse(appLink));
    intentList.add(new LabeledIntent(clipboardIntent, getPackageName(),
            getResources().getString(R.string.clipboard_activity_name), R.drawable.ic_copy_link));

    // convert intentList to array
    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

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

From source file:tv.piratemedia.lightcontroler.controller.java

private void setupApp() {

    mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
    setSupportActionBar(mActionBarToolbar);

    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    if (!prefs.getBoolean("rgbw_enabled", false) && !prefs.getBoolean("white_enabled", false)) {
        askControlType();//from   ww w .  j  ava 2 s .  c o  m
    } else {

        final ViewPager pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(new ControllerPager(getSupportFragmentManager(), this));

        tabs = (PagerSlidingTabStrip) findViewById(R.id.pager_title_strip);
        tabs.setViewPager(pager);

        if (!prefs.getBoolean("navigation_tabs", false)) {
            drawer.setProfile(new DrawerProfile().setAvatar(getResources().getDrawable(R.drawable.icon))
                    .setBackground(getResources().getDrawable(R.drawable.drawer_profile_background))
                    .setName("Light Controller"));

            mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
            mActionBarToolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);

            pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {
                    mActionBarToolbar.setTitle(pager.getAdapter().getPageTitle(position));
                }

                @Override
                public void onPageScrollStateChanged(int state) {

                }
            });
            this.setTitle(pager.getAdapter().getPageTitle(0));
            mActionBarToolbar.setTitle(pager.getAdapter().getPageTitle(0));
            tabs.setVisibility(View.GONE);

            for (int i = 0; i < pager.getAdapter().getCount(); i++) {
                if (i == 5) {
                    drawer.addDivider();
                }
                drawer.addItem(new DrawerItem().setTextMode(DrawerItem.SINGLE_LINE)
                        .setTextPrimary(pager.getAdapter().getPageTitle(i).toString())
                        .setOnItemClickListener(new DrawerItem.OnItemClickListener() {
                            @Override
                            public void onClick(DrawerItem drawerItem, int i, int i2) {
                                int item = i2;
                                if (item > 4) {
                                    item--;
                                }
                                pager.setCurrentItem(item, true);
                                drawer.closeDrawer();
                            }
                        }));
            }
            drawer.addDivider();
            drawer.addItem(new DrawerItem().setTextMode(DrawerItem.SINGLE_LINE)
                    .setTextPrimary(getResources().getString(R.string.action_settings))
                    .setOnItemClickListener(new DrawerItem.OnItemClickListener() {
                        @Override
                        public void onClick(DrawerItem drawerItem, int i, int i2) {
                            Intent intent = new Intent(getApplicationContext(), controlPreferences.class);
                            startActivity(intent);
                            finish();
                            drawer.closeDrawer();
                        }
                    }));

            final PackageManager pm = getPackageManager();
            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory("tv.piratemedia.lightcontroller.plugin");
            List<ResolveInfo> resolveInfos = pm.queryIntentActivities(mainIntent, 0);
            if (resolveInfos.size() > 0) {
                drawer.addDivider();
                for (final ResolveInfo info : resolveInfos) {
                    drawer.addItem(new DrawerItem().setTextMode(DrawerItem.SINGLE_LINE)
                            .setTextPrimary(info.loadLabel(pm).toString()).setImage(info.loadIcon(pm))
                            .setOnItemClickListener(new DrawerItem.OnItemClickListener() {
                                @Override
                                public void onClick(DrawerItem drawerItem, int i, int i2) {
                                    Intent intent = new Intent(Intent.ACTION_MAIN);
                                    Log.d("package", "pkg:" + info.resolvePackageName);
                                    intent.setComponent(new ComponentName(info.activityInfo.packageName,
                                            info.activityInfo.name));
                                    startActivity(intent);
                                    drawer.closeDrawer();
                                }
                            }));
                }
            }
        } else {
            drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        }
    }
}

From source file:com.mycelium.wallet.activity.modern.ModernMain.java

private void shareTransactionHistory() {
    WalletAccount account = _mbwManager.getSelectedAccount();
    MetadataStorage metaData = _mbwManager.getMetadataStorage();
    try {//from  ww w .j  a va  2s .  co  m
        String fileName = "MyceliumExport_" + System.currentTimeMillis() + ".csv";
        File historyData = DataExport.getTxHistoryCsv(account, metaData, getFileStreamPath(fileName));
        PackageManager packageManager = Preconditions.checkNotNull(getPackageManager());
        PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), PackageManager.GET_PROVIDERS);
        for (ProviderInfo info : packageInfo.providers) {
            if (info.name.equals("android.support.v4.content.FileProvider")) {
                String authority = info.authority;
                Uri uri = FileProvider.getUriForFile(this, authority, historyData);
                Intent intent = ShareCompat.IntentBuilder.from(this).setStream(uri) // uri from FileProvider
                        .setType("text/plain")
                        .setSubject(getResources().getString(R.string.transaction_history_title))
                        .setText(getResources().getString(R.string.transaction_history_title)).getIntent()
                        .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                List<ResolveInfo> resInfoList = packageManager.queryIntentActivities(intent,
                        PackageManager.MATCH_DEFAULT_ONLY);
                for (ResolveInfo resolveInfo : resInfoList) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
                startActivity(Intent.createChooser(intent,
                        getResources().getString(R.string.share_transaction_history)));
            }
        }
    } catch (IOException | PackageManager.NameNotFoundException e) {
        _toaster.toast("Export failed. Check your logs", false);
        e.printStackTrace();
    }
}

From source file:owne.android.envmonitor.FeaturesActivity.java

private void setupPluginsInDrawer(final ViewGroup container) {
    final LayoutInflater inflater = LayoutInflater.from(this);
    final PackageManager pm = getPackageManager();

    // look for Master Control Panel
    final Intent mcpIntent = new Intent(Intent.ACTION_MAIN);
    mcpIntent.setClassName(MCP_PACKAGE, MCP_CLASS);
    final ResolveInfo mcpInfo = pm.resolveActivity(mcpIntent, 0);

    // configure link to Master Control Panel
    final TextView mcpItem = (TextView) container.findViewById(R.id.link_mcp);
    if (mcpInfo == null) {
        mcpItem.setTextColor(Color.GRAY);
        ColorMatrix grayscale = new ColorMatrix();
        grayscale.setSaturation(0.0f);//from  w  ww . j av a 2s. c o  m
        mcpItem.getCompoundDrawables()[0].setColorFilter(new ColorMatrixColorFilter(grayscale));
    }
    mcpItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            Intent action = mcpIntent;
            if (mcpInfo == null)
                action = new Intent(Intent.ACTION_VIEW, Uri.parse(MCP_MARKET_URI));
            action.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            startActivity(action);
            mDrawerLayout.closeDrawers();
        }
    });

    // look for other plug-ins
    final Intent utilsIntent = new Intent(Intent.ACTION_MAIN);
    utilsIntent.addCategory(UTILS_CATEGORY);

    final List<ResolveInfo> appList = pm.queryIntentActivities(utilsIntent, 0);
    for (final ResolveInfo info : appList) {
        final View item = inflater.inflate(R.layout.drawer_plugin, container, false);
        final ImageView icon = (ImageView) item.findViewById(android.R.id.icon);
        final TextView label = (TextView) item.findViewById(android.R.id.text1);

        label.setText(info.loadLabel(pm));
        icon.setImageDrawable(info.loadIcon(pm));
        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                final Intent intent = new Intent();
                intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intent);
            }
        });
        container.addView(item);
    }
}

From source file:no.android.proxime.FeaturesActivity.java

private void setupPluginsInDrawer(final ViewGroup container) {
    final LayoutInflater inflater = LayoutInflater.from(this);
    final PackageManager pm = getPackageManager();

    // look for Master Control Panel
    final Intent mcpIntent = new Intent(Intent.ACTION_MAIN);
    mcpIntent.setClassName(MCP_PACKAGE, MCP_CLASS);
    final ResolveInfo mcpInfo = pm.resolveActivity(mcpIntent, 0);

    // configure link to Master Control Panel
    final TextView mcpItem = (TextView) container.findViewById(R.id.link_mcp);
    if (mcpInfo == null) {
        mcpItem.setTextColor(Color.GRAY);
        ColorMatrix grayscale = new ColorMatrix();
        grayscale.setSaturation(0.0f);//ww  w .  ja v a  2  s .  c om
        mcpItem.getCompoundDrawables()[0].setColorFilter(new ColorMatrixColorFilter(grayscale));
    }
    mcpItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            Intent action = mcpIntent;
            if (mcpInfo == null)
                action = new Intent(Intent.ACTION_VIEW, Uri.parse(MCP_MARKET_URI));
            action.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            startActivity(action);
            mDrawerLayout.closeDrawers();
        }
    });

    // look for other plug-ins
    final Intent utilsIntent = new Intent(Intent.ACTION_MAIN);
    utilsIntent.addCategory(UTILS_CATEGORY);

    final List<ResolveInfo> appList = pm.queryIntentActivities(utilsIntent, 0);
    for (final ResolveInfo info : appList) {
        final View item = inflater.inflate(R.layout.drawer_plugin, container, false);
        final ImageView icon = (ImageView) item.findViewById(android.R.id.icon);
        final TextView label = (TextView) item.findViewById(android.R.id.text1);

        label.setText(info.loadLabel(pm));
        icon.setImageDrawable(info.loadIcon(pm));
        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                final Intent intent = new Intent();
                intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intent);
                mDrawerLayout.closeDrawers();
            }
        });
        container.addView(item);
    }
}

From source file:com.brq.wallet.activity.modern.ModernMain.java

private void shareTransactionHistory() {
    WalletAccount account = _mbwManager.getSelectedAccount();
    MetadataStorage metaData = _mbwManager.getMetadataStorage();
    try {/* www. j av  a  2 s  .  c o  m*/
        String fileName = "MyceliumExport_" + System.currentTimeMillis() + ".csv";
        File historyData = DataExport.getTxHistoryCsv(account, metaData, getFileStreamPath(fileName));
        PackageManager packageManager = Preconditions.checkNotNull(getPackageManager());
        PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), PackageManager.GET_PROVIDERS);
        for (ProviderInfo info : packageInfo.providers) {
            if (info.name.equals("android.support.v4.content.FileProvider")) {
                String authority = info.authority;
                Uri uri = FileProvider.getUriForFile(this, authority, historyData);
                Intent intent = ShareCompat.IntentBuilder.from(this).setStream(uri) // uri from FileProvider
                        .setType("text/plain")
                        .setSubject(getResources().getString(R.string.transaction_history_title))
                        .setText(getResources().getString(R.string.transaction_history_title)).getIntent()
                        .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                List<ResolveInfo> resInfoList = packageManager.queryIntentActivities(intent,
                        PackageManager.MATCH_DEFAULT_ONLY);
                for (ResolveInfo resolveInfo : resInfoList) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
                startActivity(Intent.createChooser(intent,
                        getResources().getString(R.string.share_transaction_history)));
            }
        }
    } catch (IOException e) {
        _toaster.toast("Export failed. Check your logs", false);
        e.printStackTrace();
    } catch (PackageManager.NameNotFoundException e) {
        _toaster.toast("Export failed. Check your logs", false);
        e.printStackTrace();
    }
}

From source file:com.linkbubble.Settings.java

private void setDefaultLeftConsumeBubble() {
    String leftConsumeBubblePackageName = mSharedPreferences
            .getString(PREFERENCE_LEFT_CONSUME_BUBBLE_PACKAGE_NAME, null);
    if (leftConsumeBubblePackageName == null) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        PackageManager packageManager = mContext.getPackageManager();
        List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent, 0);

        if (setDefaultLeftConsumeBubble(
                findResolveInfoForPackageName(resolveInfos, Constant.POCKET_PACKAGE_NAME),
                packageManager) == false) {
            if (setDefaultLeftConsumeBubble(
                    findResolveInfoForPackageName(resolveInfos, "com.instapaper.android"),
                    packageManager) == false) {
                if (setDefaultLeftConsumeBubble(
                        findResolveInfoForPackageName(resolveInfos, "com.facebook.katana"),
                        packageManager) == false) {
                    if (setDefaultLeftConsumeBubble(
                            findResolveInfoForPackageName(resolveInfos, "com.twitter.android"),
                            packageManager) == false) {
                        if (setDefaultLeftConsumeBubble(
                                findResolveInfoForPackageName(resolveInfos, "com.google.android.apps.plus"),
                                packageManager) == false) {
                            if (setDefaultLeftConsumeBubble(
                                    findResolveInfoForPackageName(resolveInfos, "com.google.android.gm"),
                                    packageManager) == false) {
                                // Can't imagine *none* of the above apps will not be installed too often, but if so, fall back to the first item in the list...
                                setDefaultLeftConsumeBubble(resolveInfos.get(0), packageManager);
                            }/*from w w  w .j  a v  a  2s .c om*/
                        }
                    }
                }
            }
        }
    }
}