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.akalizakeza.apps.ishusho.activity.NewPostActivity.java

@AfterPermissionGranted(RC_CAMERA_PERMISSIONS)
private void showImagePicker() {
    // Check for camera permissions
    if (!EasyPermissions.hasPermissions(this, cameraPerms)) {
        EasyPermissions.requestPermissions(this, "This sample will upload a picture from your Camera",
                RC_CAMERA_PERMISSIONS, cameraPerms);
        return;//from  www  .  ja  va 2 s  .c  o  m
    }

    // Choose file storage location
    File file = new File(getExternalCacheDir(), UUID.randomUUID().toString());
    mFileUri = Uri.fromFile(file);

    // Camera
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : listCam) {
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri);
        cameraIntents.add(intent);
    }

    // Image Picker
    Intent pickerIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    Intent chooserIntent = Intent.createChooser(pickerIntent, getString(R.string.picture_chooser_title));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
    startActivityForResult(chooserIntent, TC_PICK_IMAGE);
}

From source file:com.tortel.deploytrack.MainActivity.java

/**
 * Check if there is an app available to handle an intent
  *//*  w  w  w  .ja v a2  s . c  o m*/
private boolean isAvailable(Intent intent) {
    final PackageManager mgr = getPackageManager();
    List<ResolveInfo> list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:com.nagopy.android.mypkgs.MainActivity.java

boolean canLaunchImplicitIntent(@NonNull Intent intent) {
    PackageManager packageManager = getPackageManager();
    return !packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).isEmpty();
}

From source file:com.hichinaschool.flashcards.libanki.Utils.java

public static boolean isIntentAvailable(Context context, String action, ComponentName componentName) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    intent.setComponent(componentName);//from w w  w .  ja va 2 s .c  o  m
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:at.tomtasche.reader.ui.activity.MainActivity.java

public void findDocument() {

    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    // remove mime-type because most apps don't support ODF mime-types
    intent.setType("application/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    PackageManager pm = getPackageManager();
    final List<ResolveInfo> targets = pm.queryIntentActivities(intent, 0);
    int size = targets.size();
    String[] targetNames = new String[size];
    for (int i = 0; i < size; i++) {
        targetNames[i] = targets.get(i).loadLabel(pm).toString();
    }/*ww w  .  j a va2 s .co  m*/

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.dialog_choose_filemanager);
    builder.setItems(targetNames, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            ResolveInfo target = targets.get(which);
            if (target == null) {
                return;
            }

            intent.setComponent(new ComponentName(target.activityInfo.packageName, target.activityInfo.name));

            try {
                startActivityForResult(intent, 42);
            } catch (Exception e) {
                e.printStackTrace();

                showCrouton(R.string.crouton_error_open_app, new Runnable() {

                    @Override
                    public void run() {
                        findDocument();
                    }
                }, AppMsg.STYLE_ALERT);
            }

            dialog.dismiss();
        }
    });
    builder.show();
}

From source file:com.fitc.dooropener.lib.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param status GCM message received.//from   ww w.  j  a v a 2s .  c  om
 */
private void sendNotification(GcmDataPayload status) {

    /**
     * This code should find launcher activity of app using this librbary and set it as the what gets launched
     */
    Intent intent = null;
    final PackageManager packageManager = getPackageManager();
    Log.i(TAG, "PACKAGE NAME " + getPackageName());

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

    List<ResolveInfo> appList = packageManager.queryIntentActivities(mainIntent, 0);

    for (final ResolveInfo resolveInfo : appList) {
        if (getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen)
        {
            intent = packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
            break;
        }
    }
    PendingIntent pendingIntent = null;
    if (intent != null) {
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification)
            .setContentTitle(getResources().getString(R.string.notif_content_title))
            .setContentText(status.getStatusData()).setAutoCancel(true).setSound(defaultSoundUri);

    if (pendingIntent != null) {
        notificationBuilder.setContentIntent(pendingIntent);
    }

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.mendhak.gpslogger.common.PrefsIO.java

private void BrowseFile() {
    Intent chooseFile;//from  w  w w  .  j  a  v  a 2 s  .  co m
    Intent intent;
    chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
    chooseFile.setType("file/*");
    final PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> list = packageManager.queryIntentActivities(chooseFile, 0);
    if (list.size() > 0) {
        intent = Intent.createChooser(chooseFile, context.getString(R.string.ChooseFile));
        Utilities.LogDebug("Trying to start file browser...");
        ((Activity) context).startActivityForResult(intent, ACTIVITY_CHOOSE_FILE);
    } else
        Toast.makeText(context, context.getString(R.string.NoFSBrowser), Toast.LENGTH_SHORT).show();
}

From source file:net.frakbot.FWeather.util.FeedbackService.java

/**
 * Determines if there is at least one component in the system that is able
 * to actually send feedbacks (usually it's the Play Store, but we've seen
 * this fail in at least one case).//from ww w.ja  v  a 2 s  .  co m
 *
 * @return Returns true if the feedback Intent can be handled, false otherwise.
 */
private boolean canSendPlayStoreFeedback() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // Built-in reporting only works from Android 4.0 onwards
        return false;
    }

    Intent intent = new Intent(Intent.ACTION_APP_ERROR);

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

    return list != null && list.size() > 0;
}

From source file:com.negaheno.android.NotificationsController.java

public static String getLauncherClassName(Context context) {
    try {/*from   ww w.  ja  v a  2 s  . c  o  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("tmessages", e);
    }
    return null;
}

From source file:com.tdispatch.passenger.fragment.SearchAddressFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle args = getArguments();//from w  ww  .jav  a 2s  .c o  m
    if (args != null) {
        mType = args.getInt(Const.Bundle.TYPE);
        mAddress = args.getParcelable(Const.Bundle.LOCATION);
    } else {
        throw new IllegalArgumentException("Arguments not passed");
    }

    // Check to see if a voice recognition activity is present on device
    PackageManager pm = mContext.getPackageManager();
    List<ResolveInfo> activities = pm
            .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    mVoiceSearchAvailable = (activities.size() != 0);
}