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.gigaset.home.Home.java

/**
 * Loads the list of installed applications in mApplications.
 *//*from   ww w  .  j a va  2  s. c  o  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();

        ApplicationInfo application;
        // ********************* ADD Key Pad **********************************
        application = new ApplicationInfo();
        application.title = "Key Pad";
        application.icon = application.icon = getResources().getDrawable(R.drawable.main_screen_iocon_key_pad);
        application.setActivity(
                new ComponentName("com.android.contacts", "com.android.contacts.activities.DialtactsActivity"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        // ********************* ADD Messages *********************************
        application = new ApplicationInfo();
        application.title = "Messages";
        application.icon = application.icon = getResources().getDrawable(R.drawable.main_screen_icon_messages);
        application.setActivity(new ComponentName("com.android.mms", "com.android.mms.ui.ConversationList"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        // ********************* ADD Contacts *********************************
        application = new ApplicationInfo();
        application.title = "Contacts";
        application.icon = application.icon = getResources().getDrawable(R.drawable.main_screen_icon_contacts);
        application.setActivity(
                new ComponentName("com.android.contacts", "com.android.contacts.activities.PeopleActivity"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        // ********************* ADD Call Log *********************************
        // http://hi-android.info/src/index.html            
        application = new ApplicationInfo();
        application.title = "Call List";
        application.icon = getResources().getDrawable(R.drawable.main_screen_icon_call_log);

        application.setActivityWithAction(Intent.ACTION_VIEW, CallLog.Calls.CONTENT_TYPE);
        mApplications.add(application);

        // ********************* ADD Browser **********************************
        application = new ApplicationInfo();
        application.title = "Browser";
        application.icon = application.icon = getResources().getDrawable(R.drawable.main_screen_icon_browser);
        application.setActivity(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        // ********************* ADD Call Settings ****************************
        application = new ApplicationInfo();
        application.title = "Call Settings";
        application.icon = application.icon = getResources()
                .getDrawable(R.drawable.main_screen_icon_call_settings);
        application.setActivity(new ComponentName("com.android.settings", "com.android.settings.Settings"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        //            
        //            for (int i = 0; i < count; i++) 
        //            {
        //                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);
        //                
        //                // Replace Icons
        //                if((application.title+"").equals("Browser"))    application.icon = getResources().getDrawable(R.drawable.main_screen_icon_browser);
        //                if((application.title+"").equals("Phone"))       application.icon = getResources().getDrawable(R.drawable.main_screen_iocon_key_pad);
        //                if((application.title+"").equals("People"))    application.icon = getResources().getDrawable(R.drawable.main_screen_icon_contacts);
        //                if((application.title+"").equals("Messaging"))    application.icon = getResources().getDrawable(R.drawable.main_screen_icon_messages);
        //                if((application.title+"").equals("Settings"))    application.icon = getResources().getDrawable(R.drawable.main_screen_icon_call_settings);
        //                //if((application.title+"").equals("Call Log")) application.icon = getResources().getDrawable(R.drawable.main_screen_icon_call_log);
        //                
        //                // 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);
        //
        //            }

    }
}

From source file:com.google.zxing.client.android.result.ResultHandler.java

final void openGoogleShopper(String query) {

    // Construct Intent to launch Shopper
    Intent intent = new Intent(Intent.ACTION_SEARCH);
    intent.setClassName(GOOGLE_SHOPPER_PACKAGE, GOOGLE_SHOPPER_ACTIVITY);
    intent.putExtra(SearchManager.QUERY, query);

    // Is it available?
    PackageManager pm = activity.getPackageManager();
    Collection<?> availableApps = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

    if (availableApps != null && !availableApps.isEmpty()) {
        // If something can handle it, start it
        activity.startActivity(intent);/*from w ww . j  av a  2  s  . c om*/
    } else {
        // Otherwise offer to install it from Market.
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle(R.string.msg_google_shopper_missing);
        builder.setMessage(R.string.msg_install_google_shopper);
        builder.setIcon(R.drawable.shopper_icon);
        builder.setPositiveButton(R.string.button_ok, shopperMarketListener);
        builder.setNegativeButton(R.string.button_cancel, null);
        builder.show();
    }
}

From source file:atlc.granadaaccessibilityranking.VoiceActivity.java

/**
 * Creates the speech recognizer and text-to-speech synthesizer instances
 * @see RecognitionListener.java//  www.  j  ava2  s  .  co m
 * @param ctx context of the interaction
 * */
public void initSpeechInputOutput(Activity ctx) {

    this.ctx = ctx;
    PackageManager packManager = ctx.getPackageManager();

    setTTS();

    // Find out whether speech recognition is supported
    List<ResolveInfo> intActivities = packManager
            .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    if (intActivities.size() != 0 || "generic".equals(Build.BRAND.toLowerCase(Locale.US))) {
        myASR = SpeechRecognizer.createSpeechRecognizer(ctx);
        myASR.setRecognitionListener(this);
    } else
        myASR = null;
}

From source file:com.ijsbrandslob.appirater.Appirater.java

public void launchPlayStore() {
    PackageManager packageManager = mContext.getPackageManager();
    Uri marketUri = Uri.parse(String.format("market://details?id=%s", mContext.getPackageName()));
    Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(marketUri);

    List<?> list = packageManager.queryIntentActivities(marketIntent, PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {
        mContext.startActivity(marketIntent);
    } else {//from   ww  w  .  jav a 2  s. co  m
        Uri webUri = Uri.parse(
                String.format("http://play.google.com/store/apps/details?id=%s", mContext.getPackageName()));
        Intent webIntent = new Intent(Intent.ACTION_VIEW).setData(webUri);
        mContext.startActivity(webIntent);
    }
}

From source file:edu.mit.mobile.android.demomode.DemoMode.java

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

    final PackageManager manager = getPackageManager();

    final 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++) {
            final ApplicationInfo application = new ApplicationInfo();
            final 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);
            application.icon = info.activityInfo.loadIcon(manager);

            mApplications.add(application);
        }
    }
}

From source file:com.b44t.messenger.NotificationsController.java

private static String getLauncherClassName(Context context) {
    try {/* w  w  w. j a  v a2  s. co m*/
        PackageManager pm = context.getPackageManager();

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
        for (ResolveInfo resolveInfo : resolveInfos) {
            String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
            if (pkgName.equalsIgnoreCase(context.getPackageName())) {
                return resolveInfo.activityInfo.name;
            }
        }
    } catch (Throwable e) {
        FileLog.e("messenger", e);
    }
    return null;
}

From source file:uk.co.ashtonbrsc.intentexplode.Explode.java

private void checkAndShowMatchingActivites() {

    activitiesLayout.removeAllViews();/*from www  .  j  a va  2  s.  com*/
    PackageManager pm = getPackageManager();
    List<ResolveInfo> resolveInfo = pm.queryIntentActivities(editableIntent, 0);

    // Remove Intent Intercept from matching activities
    int numberOfMatchingActivities = resolveInfo.size() - 1;

    if (numberOfMatchingActivities < 1) {
        resendIntentButton.setEnabled(false);
        activitiesHeader.setText(getResources().getString(R.string.no_activities_match_intent));
    } else {
        resendIntentButton.setEnabled(true);
        activitiesHeader.setText(getResources().getQuantityString(R.plurals.activities_match_intent,
                numberOfMatchingActivities, numberOfMatchingActivities));
        for (int i = 0; i <= numberOfMatchingActivities; i++) {
            ResolveInfo info = resolveInfo.get(i);
            ActivityInfo activityinfo = info.activityInfo;
            if (!activityinfo.packageName.equals(getPackageName())) {
                addTextToLayout(
                        activityinfo.loadLabel(pm) + getResources().getString(R.string.open_bracket)
                                + activityinfo.packageName + getResources().getString(R.string.dash)
                                + activityinfo.name + getResources().getString(R.string.close_bracket),
                        Typeface.NORMAL, activitiesLayout);
            }
        }
    }
}

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

private void preferPackageForIntent(Intent intent, String packageName) {
    PackageManager pm = getContext().getPackageManager();
    for (ResolveInfo resolveInfo : pm.queryIntentActivities(intent, 0)) {
        if (resolveInfo.activityInfo.packageName.equals(packageName)) {
            intent.setPackage(packageName);
            break;
        }/*from www  . j  av a  2s  . c om*/
    }
}

From source file:edu.sfsu.csc780.chathub.ui.MainActivity.java

private void dispatchTakePhotoIntent() {
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager packageManager = getPackageManager();
    List<ResolveInfo> activities = packageManager.queryIntentActivities(cameraIntent, 0);
    boolean isIntentSafe = activities.size() > 0;
    featureFlag = 1;//from  w ww  . j  av a 2s.co  m

    if (isIntentSafe) {
        startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
    }
}

From source file:edu.sfsu.csc780.chathub.ui.MainActivity.java

private void dispatchRecordVideoIntent() {
    Intent cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    PackageManager packageManager = getPackageManager();
    List<ResolveInfo> activities = packageManager.queryIntentActivities(cameraIntent, 0);
    boolean isIntentSafe = activities.size() > 0;
    featureFlag = 2;/*from   w  w  w  .  j  a  v  a2s. c om*/

    if (isIntentSafe) {
        startActivityForResult(cameraIntent, REQUEST_VIDEO_CAPTURE);
    }
}