Example usage for android.content.pm PackageManager MATCH_DEFAULT_ONLY

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

Introduction

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

Prototype

int MATCH_DEFAULT_ONLY

To view the source code for android.content.pm PackageManager MATCH_DEFAULT_ONLY.

Click Source Link

Document

Resolution and querying flag: if set, only filters that support the android.content.Intent#CATEGORY_DEFAULT will be considered for matching.

Usage

From source file:org.kontalk.ui.ComposeMessageFragment.java

/** Starts an activity for shooting a picture. */
private void selectPhotoAttachment() {
    try {/*from   w ww  .  j a v a 2  s.c om*/
        // check if camera is available
        final PackageManager packageManager = getActivity().getPackageManager();
        final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (list.size() <= 0)
            throw new UnsupportedOperationException();

        mCurrentPhoto = MediaStorage.getOutgoingImageFile();
        Uri uri = Uri.fromFile(mCurrentPhoto);
        Intent take = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        take.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            take.setClipData(ClipData.newUri(getContext().getContentResolver(), "Picture path", uri));
        }

        startActivityForResult(take, SELECT_ATTACHMENT_PHOTO);
    } catch (UnsupportedOperationException ue) {
        Toast.makeText(getActivity(), R.string.chooser_error_no_camera_app, Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        Log.e(TAG, "error creating temp file", e);
        Toast.makeText(getActivity(), R.string.chooser_error_no_camera, Toast.LENGTH_LONG).show();
    }
}

From source file:com.android.gallery3d.app.PhotoPage.java

private void launchPhotoEditor() {
    /// M: [BUG.ADD] abort editing photo if loading fail @{
    if (mModel != null && mModel.getLoadingState(0) == PhotoView.Model.LOADING_FAIL) {
        Log.i(TAG, "<launchPhotoEditor> abort editing photo if loading fail!");
        Toast.makeText(mActivity, mActivity.getString(R.string.cannot_load_image), Toast.LENGTH_SHORT).show();
        return;/*w  w w. jav a2  s  .  c  o m*/
    }
    /// @}
    MediaItem current = mModel.getMediaItem(0);
    if (current == null || (current.getSupportedOperations() & MediaObject.SUPPORT_EDIT) == 0) {
        return;
    }

    Intent intent = new Intent(ACTION_NEXTGEN_EDIT);

    /// M: [BUG.MODIFY] create new task when launch photo editor from camera
    // gallery and photo editor use same task stack @{
    /*
    intent.setDataAndType(current.getContentUri(), current.getMimeType())
          .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    */
    intent.setDataAndType(current.getContentUri(), current.getMimeType())
            .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
    /// @}
    if (mActivity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
            .size() == 0) {
        intent.setAction(Intent.ACTION_EDIT);
    }
    intent.putExtra(FilterShowActivity.LAUNCH_FULLSCREEN, mActivity.isFullscreen());
    /// M: [FEATURE.ADD] @{
    // for special image, no need to delete origin image when save, such as continuous shot
    ExtItem extItem = current.getExtItem();
    if (extItem != null && !extItem.isDeleteOriginFileAfterEdit()) {
        // if current photo is last image in continuous shot group, not
        // set NEED_SAVE_AS as true
        if (mModel instanceof PhotoDataAdapter) {
            int size = ((PhotoDataAdapter) mModel).getTotalCount();
            MediaData md = current.getMediaData();
            if (size == 1 && md.mediaType == MediaData.MediaType.NORMAL
                    && md.subType == MediaData.SubType.CONSHOT) {
                intent.putExtra(FilterShowActivity.NEED_SAVE_AS, false);
                Log.i(TAG, "<launchPhotoEditor> edit the last image in continuous shot group,"
                        + " not set NEED_SAVE_AS as true");
            } else {
                intent.putExtra(FilterShowActivity.NEED_SAVE_AS, true);
            }
        } else {
            intent.putExtra(FilterShowActivity.NEED_SAVE_AS, true);
        }
    }
    /// @}

    /// M: [BUG.MODIFY] @{
    // Make ChooserActivity and GalleryActivity in different tasks.
    /*
     * ((Activity)mActivity).startActivityForResult(Intent.createChooser(intent
     * , null), REQUEST_EDIT);
     */
    ((Activity) mActivity).startActivityForResult(
            Intent.createChooser(intent, null).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), REQUEST_EDIT);
    /// @}

    overrideTransitionToEditor();
}

From source file:com.android.contacts.activities.PeopleActivity.java

private boolean hasExportIntentHandler() {
    final Intent intent = new Intent();
    intent.setAction("com.android.providers.contacts.DUMP_DATABASE");
    final List<ResolveInfo> receivers = getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return receivers != null && receivers.size() > 0;
}

From source file:com.android.gallery3d.app.PhotoPage.java

private void launchSimpleEditor() {
    MediaItem current = mModel.getMediaItem(0);
    if (current == null || (current.getSupportedOperations() & MediaObject.SUPPORT_EDIT) == 0) {
        return;/*from   w ww  .  j  av a  2 s. co m*/
    }

    Intent intent = new Intent(ACTION_SIMPLE_EDIT);

    intent.setDataAndType(current.getContentUri(), current.getMimeType())
            .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    if (mActivity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
            .size() == 0) {
        intent.setAction(Intent.ACTION_EDIT);
    }
    intent.putExtra(FilterShowActivity.LAUNCH_FULLSCREEN, mActivity.isFullscreen());
    ((Activity) mActivity).startActivityForResult(Intent.createChooser(intent, null), REQUEST_EDIT);
    overrideTransitionToEditor();
}

From source file:com.android.dialer.DialtactsActivity.java

private boolean canIntentBeHandled(Intent intent) {
    final PackageManager packageManager = getPackageManager();
    final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return resolveInfo != null && resolveInfo.size() > 0;
}

From source file:activities.PaintActivity.java

@Override
public void onCompartirButtonClicked() {

    final Resources resources = getResources();

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

    final List<String> listStringPackages = new ArrayList<String>();

    List<ResolveInfo> apps = pm.queryIntentActivities(sendIntent, PackageManager.MATCH_DEFAULT_ONLY);
    Iterator i = apps.iterator();
    //Aca creamos nuestro filtro de apps especificas
    while (i.hasNext()) {
        ResolveInfo app = (ResolveInfo) i.next();
        String packageName = app.activityInfo.applicationInfo.packageName;
        if (packageName.contains("facebook") || packageName.contains("twitter") || packageName.contains("gm")) {
            listStringPackages.add(packageName);
        }/*from w w w.java  2s  .  c om*/

    }

    ArrayAdapter<String> adapter = new ShareChooserAdapter(this, android.R.layout.select_dialog_item,
            android.R.id.text1, listStringPackages);

    new AlertDialog.Builder(this).setTitle(string.sharechooser_title)
            .setAdapter(adapter, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    invokeApplication(listStringPackages.get(i), resources);
                }
            }).setCancelable(true).setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    Log.d("DialogShare", "canceled, se borra la imagen...");
                }
            }).show();

}

From source file:net.ddns.mlsoftlaberge.contactslist.ui.ContactAdminFragment.java

/**
 * Builds an address LinearLayout based on address information from the Contacts Provider.
 * Each address for the contact gets its own LinearLayout object; for example, if the contact
 * has three postal addresses, then 3 LinearLayouts are generated.
 *
 * @param addressType      From//ww w . ja  v a2s. co m
 *                         {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#TYPE}
 * @param addressTypeLabel From
 *                         {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#LABEL}
 * @param address          From
 *                         {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#FORMATTED_ADDRESS}
 * @return A LinearLayout to add to the contact details layout,
 * populated with the provided address details.
 */
private LinearLayout buildAddressLayout(int addressType, String addressTypeLabel, final String address) {

    // Inflates the address layout
    final LinearLayout addressLayout = (LinearLayout) LayoutInflater.from(getActivity())
            .inflate(R.layout.contact_address_item, mAddressLayout, false);

    // Gets handles to the view objects in the layout
    final TextView headerTextView = (TextView) addressLayout.findViewById(R.id.contact_address_header);
    final TextView addressTextView = (TextView) addressLayout.findViewById(R.id.contact_address_full);
    final ImageButton viewAddressButton = (ImageButton) addressLayout.findViewById(R.id.button_view_address);

    // If there's no addresses for the contact, shows the empty view and message, and hides the
    // header and button.
    if (addressTypeLabel == null && addressType == 0) {
        headerTextView.setVisibility(View.GONE);
        viewAddressButton.setVisibility(View.GONE);
        addressTextView.setText(R.string.no_address);
    } else {
        // Gets postal address label type
        CharSequence label = StructuredPostal.getTypeLabel(getResources(), addressType, addressTypeLabel);

        // Sets TextView objects in the layout
        headerTextView.setText(label + " Address");
        addressTextView.setText(address);
        viewAddressButton.setContentDescription(address);

        // Defines an onClickListener object for the address button
        viewAddressButton.setOnClickListener(new View.OnClickListener() {
            // Defines what to do when users click the address button
            @Override
            public void onClick(View view) {

                final Intent viewIntent = new Intent(Intent.ACTION_VIEW,
                        constructGeoUri(view.getContentDescription().toString()));

                // A PackageManager instance is needed to verify that there's a default app
                // that handles ACTION_VIEW and a geo Uri.
                final PackageManager packageManager = getActivity().getPackageManager();

                // Checks for an activity that can handle this intent. Preferred in this
                // case over Intent.createChooser() as it will still let the user choose
                // a default (or use a previously set default) for geo Uris.
                if (packageManager.resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
                    // Toast.makeText(getActivity(),
                    //        R.string.yes_intent_found, Toast.LENGTH_SHORT).show();
                    startActivity(viewIntent);
                } else {
                    // If no default is found, displays a message that no activity can handle
                    // the view button.
                    Toast.makeText(getActivity(), R.string.no_intent_found, Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
    return addressLayout;
}

From source file:net.ddns.mlsoftlaberge.trycorder.contacts.ContactAdminFragment.java

/**
 * Builds an address LinearLayout based on address information from the Contacts Provider.
 * Each address for the contact gets its own LinearLayout object; for example, if the contact
 * has three postal addresses, then 3 LinearLayouts are generated.
 *
 * @param addressType      From//w ww.j  av a  2s . c o  m
 *                         {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#TYPE}
 * @param addressTypeLabel From
 *                         {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#LABEL}
 * @param address          From
 *                         {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#FORMATTED_ADDRESS}
 * @return A LinearLayout to add to the contact details layout,
 * populated with the provided address details.
 */
private LinearLayout buildAddressLayout(int addressType, String addressTypeLabel, final String address) {

    // Inflates the address layout
    final LinearLayout addressLayout = (LinearLayout) LayoutInflater.from(getActivity())
            .inflate(R.layout.contact_address_item, mAddressLayout, false);

    // Gets handles to the view objects in the layout
    final TextView headerTextView = (TextView) addressLayout.findViewById(R.id.contact_address_header);
    final TextView addressTextView = (TextView) addressLayout.findViewById(R.id.contact_address_full);
    final ImageButton viewAddressButton = (ImageButton) addressLayout.findViewById(R.id.button_view_address);

    // If there's no addresses for the contact, shows the empty view and message, and hides the
    // header and button.
    if (addressTypeLabel == null && addressType == 0) {
        headerTextView.setVisibility(View.GONE);
        viewAddressButton.setVisibility(View.GONE);
        addressTextView.setText(R.string.no_address);
    } else {
        // Gets postal address label type
        CharSequence label = StructuredPostal.getTypeLabel(getResources(), addressType, addressTypeLabel);

        // Sets TextView objects in the layout
        headerTextView.setText(label + " Address");
        addressTextView.setText(address);
        viewAddressButton.setContentDescription(address);

        // Defines an onClickListener object for the address button
        viewAddressButton.setOnClickListener(new View.OnClickListener() {
            // Defines what to do when users click the address button
            @Override
            public void onClick(View view) {
                buttonsound();

                final Intent viewIntent = new Intent(Intent.ACTION_VIEW,
                        constructGeoUri(view.getContentDescription().toString()));

                // A PackageManager instance is needed to verify that there's a default app
                // that handles ACTION_VIEW and a geo Uri.
                final PackageManager packageManager = getActivity().getPackageManager();

                // Checks for an activity that can handle this intent. Preferred in this
                // case over Intent.createChooser() as it will still let the user choose
                // a default (or use a previously set default) for geo Uris.
                if (packageManager.resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
                    // Toast.makeText(getActivity(),
                    //        R.string.yes_intent_found, Toast.LENGTH_SHORT).show();
                    startActivity(viewIntent);
                } else {
                    // If no default is found, displays a message that no activity can handle
                    // the view button.
                    Toast.makeText(getActivity(), R.string.no_intent_found, Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
    return addressLayout;
}

From source file:github.daneren2005.dsub.fragments.SubsonicFragment.java

protected void playExternalPlayer(Entry entry) {
    if (!entryExists(entry)) {
        Util.toast(context, R.string.download_need_download);
    } else {//ww w  .  j a  v a 2 s .c o  m
        DownloadFile check = new DownloadFile(context, entry, false);
        File file = check.getCompleteFile();

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file), "video/*");
        intent.putExtra(Intent.EXTRA_TITLE, entry.getTitle());

        List<ResolveInfo> intents = context.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (intents != null && intents.size() > 0) {
            startActivity(intent);
        } else {
            Util.toast(context, R.string.download_no_streaming_player);
        }
    }
}