Example usage for android.content Intent EXTRA_MIME_TYPES

List of usage examples for android.content Intent EXTRA_MIME_TYPES

Introduction

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

Prototype

String EXTRA_MIME_TYPES

To view the source code for android.content Intent EXTRA_MIME_TYPES.

Click Source Link

Document

Extra used to communicate a set of acceptable MIME types.

Usage

From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java

private void buildDefaultState() {
    mState = new State();

    final Intent intent = virtualIntent;
    final String action = intent.getAction();
    if (Intent.ACTION_OPEN_DOCUMENT.equals(action)) {
        mState.action = ACTION_OPEN;/*  w w  w. j a  v  a2  s  .  c o  m*/
    } else if (Intent.ACTION_CREATE_DOCUMENT.equals(action)) {
        mState.action = ACTION_CREATE;
    } else if (Intent.ACTION_GET_CONTENT.equals(action)) {
        mState.action = ACTION_GET_CONTENT;
    } else if (DocumentsContract.ACTION_MANAGE_ROOT.equals(action)) {
        mState.action = ACTION_MANAGE;
    }

    if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
        mState.allowMultiple = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
    }

    if (mState.action == ACTION_MANAGE) {
        mState.acceptMimes = new String[] { "*/*" };
        mState.allowMultiple = true;
    } else if (intent.hasExtra(Intent.EXTRA_MIME_TYPES)) {
        mState.acceptMimes = intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES);
    } else {
        mState.acceptMimes = new String[] { intent.getType() };
    }

    mState.localOnly = intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false);
    mState.forceAdvanced = intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false);
    mState.showAdvanced = mState.forceAdvanced | SettingsActivity.getDisplayAdvancedDevices(this);
}

From source file:com.github.mjdev.libaums.usbfileman.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.create_file:
        new NewFileDialog().show(getFragmentManager(), "NEW_FILE");
        return true;
    case R.id.create_dir:
        new NewDirDialog().show(getFragmentManager(), "NEW_DIR");
        return true;
    case R.id.create_big_file:
        createBigFile();//from ww  w .  jav  a2  s .  com
        return true;
    case R.id.paste:
        move();
        return true;
    case R.id.stop_http_server:
        if (serverService != null) {
            serverService.stopServer();
        }
        return true;
    case R.id.run_tests:
        startActivity(new Intent(this, LibAumsTest.class));
        return true;
    case R.id.open_storage_provider:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (device != null) {
                Log.d(TAG, "Closing device first");
                device.close();
            }
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("*/*");
            String[] extraMimeTypes = { "image/*", "video/*" };
            intent.putExtra(Intent.EXTRA_MIME_TYPES, extraMimeTypes);
            intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
            startActivityForResult(intent, OPEN_STORAGE_PROVIDER_RESULT);
        }
        return true;
    case R.id.copy_from_storage_provider:

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("*/*");

            startActivityForResult(intent, COPY_STORAGE_PROVIDER_RESULT);
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }

}

From source file:com.android.mms.ui.MessageUtils.java

public static void selectAudio(Activity activity, int requestCode) {
    // / M: Code analyze 027, new feature, to improve the performance of
    // Mms. @{/*w  w  w .j ava 2  s.  co m*/
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(MmsContentType.AUDIO_UNSPECIFIED);
    String[] mimeTypess = new String[] { MmsContentType.AUDIO_UNSPECIFIED, MmsContentType.AUDIO_OGG,
            "application/x-ogg" };
    intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypess);
    if (FeatureOption.MTK_DRM_APP) {
        intent.putExtra(OmaDrmStore.DrmIntentExtra.EXTRA_DRM_LEVEL, OmaDrmStore.DrmIntentExtra.LEVEL_SD);
    }
    /// @}
    activity.startActivityForResult(intent, requestCode);
}

From source file:com.fa.mastodon.activity.ComposeActivity.java

private void initiateMediaPicking() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        intent.setType("image/* video/*");
    } else {/*from w  w  w .  j  ava  2 s  .c  o m*/
        String[] mimeTypes = new String[] { "image/*", "video/*" };
        intent.setType("*/*");
        intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
    }
    startActivityForResult(intent, MEDIA_PICK_RESULT);
}

From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private boolean openDocument() {
    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    final String[] mimeTypes = { "image/png", "image/jpeg", "image/gif" };
    intent.setType("image/*");
    intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    try {/*from   w w w.j a v  a  2 s .  co  m*/
        startActivityForResult(intent, REQUEST_OPEN_DOCUMENT);
    } catch (final ActivityNotFoundException e) {
        return false;
    }
    return true;
}

From source file:com.keylesspalace.tusky.ComposeActivity.java

private void initiateMediaPicking() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    String[] mimeTypes = new String[] { "image/*", "video/*" };
    intent.setType("*/*");//  ww  w .ja v a 2s. com
    intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
    startActivityForResult(intent, MEDIA_PICK_RESULT);
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public void openGallery(final ActionListener response, int type) {
    if (!isGalleryTypeSupported(type)) {
        throw new IllegalArgumentException("Gallery type " + type + " not supported on this platform.");
    }//from  www.j a  va2s  . c om
    if (getActivity() == null) {
        throw new RuntimeException("Cannot open galery in background mode");
    }
    if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,
            "This is required to browse the photos")) {
        return;
    }
    if (editInProgress()) {
        stopEditing(true);
    }
    final boolean multi;
    switch (type) {
    case Display.GALLERY_ALL_MULTI:
        multi = true;
        type = Display.GALLERY_ALL;
        break;
    case Display.GALLERY_VIDEO_MULTI:
        multi = true;
        type = Display.GALLERY_VIDEO;
        break;
    case Display.GALLERY_IMAGE_MULTI:
        multi = true;
        type = Display.GALLERY_IMAGE;
        break;
    case -9998:
        multi = true;
        type = -9999;
        break;
    default:
        multi = false;
    }

    callback = new EventDispatcher();
    callback.addListener(response);
    Intent galleryIntent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    if (multi) {
        galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    }
    if (type == Display.GALLERY_VIDEO) {
        galleryIntent.setType("video/*");
    } else if (type == Display.GALLERY_IMAGE) {
        galleryIntent.setType("image/*");
    } else if (type == Display.GALLERY_ALL) {
        galleryIntent.setType("image/* video/*");
    } else if (type == -9999) {
        galleryIntent = new Intent();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            galleryIntent.setAction(Intent.ACTION_OPEN_DOCUMENT);
        } else {
            galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
        }
        galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);

        // set MIME type for image
        galleryIntent.setType("*/*");
        galleryIntent.putExtra(Intent.EXTRA_MIME_TYPES,
                Display.getInstance().getProperty("android.openGallery.accept", "*/*").split(","));
    } else {
        galleryIntent.setType("*/*");
    }
    this.getActivity().startActivityForResult(galleryIntent, multi ? OPEN_GALLERY_MULTI : OPEN_GALLERY);
}