Example usage for android.content Intent setDataAndTypeAndNormalize

List of usage examples for android.content Intent setDataAndTypeAndNormalize

Introduction

In this page you can find the example usage for android.content Intent setDataAndTypeAndNormalize.

Prototype

public @NonNull Intent setDataAndTypeAndNormalize(@NonNull Uri data, @Nullable String type) 

Source Link

Document

(Usually optional) Normalize and set both the data Uri and an explicit MIME data type.

Usage

From source file:com.proofhq.Open.java

/**
 * Creates an intent for the data of mime type
 *
 * @param path//from   w ww. j a v a 2s .c o  m
 * @param callbackContext
 */
private void chooseIntent(String path, CallbackContext callbackContext) {
    if (path != null && path.length() > 0) {
        try {
            Uri uri = Uri.parse(path);
            String mime = getMimeType(path);
            Intent fileIntent = new Intent(Intent.ACTION_VIEW);

            if (Build.VERSION.SDK_INT > 15) {
                fileIntent.setDataAndTypeAndNormalize(uri, mime); // API Level 16 -> Android 4.1
            } else {
                fileIntent.setDataAndType(uri, mime);
            }

            cordova.getActivity().startActivity(fileIntent);

            callbackContext.success();
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
            callbackContext.error(1);
        }
    } else {
        callbackContext.error(2);
    }
}

From source file:com.waz.zclient.controllers.notifications.NotificationsController.java

private PendingIntent getGalleryIntent(Uri uri) {
    // TODO: AN-2276 - Replace with ShareCompat.IntentBuilder
    Intent galleryIntent = new Intent(Intent.ACTION_VIEW);
    galleryIntent.setDataAndTypeAndNormalize(uri, "image/*");
    galleryIntent.setClipData(new ClipData(null, new String[] { "image/*" }, new ClipData.Item(uri)));
    galleryIntent.putExtra(Intent.EXTRA_STREAM, uri);
    return PendingIntent.getActivity(context, 0, galleryIntent, 0);
}

From source file:com.android.nfc.beam.BeamTransferManager.java

Intent buildViewIntent() {
    if (mPaths.size() == 0)
        return null;

    Intent viewIntent = new Intent(Intent.ACTION_VIEW);

    String filePath = mPaths.get(0);
    Uri mediaUri = mMediaUris.get(filePath);
    Uri uri = mediaUri != null ? mediaUri
            : FileProvider.getUriForFile(mContext, "com.google.android.nfc.fileprovider", new File(filePath));
    viewIntent.setDataAndTypeAndNormalize(uri, mMimeTypes.get(filePath));
    viewIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
            | Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    return viewIntent;
}