Example usage for android.content Intent CATEGORY_OPENABLE

List of usage examples for android.content Intent CATEGORY_OPENABLE

Introduction

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

Prototype

String CATEGORY_OPENABLE

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

Click Source Link

Document

Used to indicate that an intent only wants URIs that can be opened with ContentResolver#openFileDescriptor(Uri,String) .

Usage

From source file:de.j4velin.encrypter.EncryptedFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_filelist, container, false);
    Database db = new Database(getContext());
    adapter = new FileAdapter(getContext(), new FileAdapter.ClickListener() {
        @Override//from  w w w  . ja  va  2 s.  c o m
        public void click(final File file) {
            selectedFile = file;
            Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType(selectedFile.mime);
            intent.putExtra(Intent.EXTRA_TITLE, selectedFile.name);
            EncryptedFragment.this.startActivityForResult(intent, REQUEST_OUTPUT);
        }
    }, new FileAdapter.DeleteListener() {
        @Override
        public boolean delete(final File file) {
            java.io.File f = new java.io.File(file.uri.getPath());
            if (!f.exists() || f.delete()) {
                Database db = new Database(getContext());
                db.deleteFile(file.id);
                db.close();
                return true;
            } else {
                return false;
            }
        }
    }, db.getFiles());
    db.close();
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setAdapter(adapter);
    return recyclerView;
}

From source file:com.runzii.paintmooc.ui.fragments.StorageClientFragment.java

/**
 * Fires an intent to spin up the "file chooser" UI and select an image.
 *///  ww  w  . j a v  a  2 s  .  c o m
public void performFileSearch() {

    // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file browser.
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

    // Filter to only show results that can be "opened", such as a file (as opposed to a list
    // of contacts or timezones)
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // Filter to show only images, using the image MIME data type.
    // If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
    // To search for all documents available via installed storage providers, it would be
    // "*/*".
    intent.setType("image/*");

    startActivityForResult(intent, READ_REQUEST_CODE);
}

From source file:com.example.android.storageclient.StorageClientFragment.java

/**
 * Fires an intent to spin up the "file chooser" UI and select an image.
 *//*ww w .  j  a  v  a 2s.  c  om*/
public void performFileSearch() {

    // BEGIN_INCLUDE (use_open_document_intent)
    // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file browser.
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

    // Filter to only show results that can be "opened", such as a file (as opposed to a list
    // of contacts or timezones)
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // Filter to show only images, using the image MIME data type.
    // If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
    // To search for all documents available via installed storage providers, it would be
    // "*/*".
    intent.setType("image/*");

    startActivityForResult(intent, READ_REQUEST_CODE);
    // END_INCLUDE (use_open_document_intent)
}

From source file:org.kde.kdeconnect.Plugins.SharePlugin.SendFileActivity.java

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

    mDeviceId = getIntent().getStringExtra("deviceId");

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    try {/*from ww  w. j  a va  2 s .  c  om*/
        startActivityForResult(Intent.createChooser(intent, getString(R.string.send_files)),
                Activity.RESULT_FIRST_USER);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(this, R.string.no_file_browser, Toast.LENGTH_SHORT).show();
        finish();
    }
}

From source file:org.sufficientlysecure.keychain.util.FileHelper.java

/** Opens the storage browser on Android 4.4 or later for saving a file. */
@TargetApi(VERSION_CODES.KITKAT)//  w  w  w.j  a v  a  2  s. c  o m
public static void saveDocument(Fragment fragment, String suggestedName, String mimeType, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(mimeType);
    // Note: This is not documented, but works: Show the Internal Storage menu item in the drawer!
    intent.putExtra("android.content.extra.SHOW_ADVANCED", true);
    intent.putExtra(Intent.EXTRA_TITLE, suggestedName);
    fragment.startActivityForResult(intent, requestCode);
}

From source file:com.synox.android.ui.dialog.UploadSourceDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    String[] allTheItems = { getString(R.string.actionbar_upload_files),
            getString(R.string.actionbar_upload_from_apps) };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), getTheme());
    builder.setTitle(R.string.actionbar_upload);
    builder.setItems(allTheItems, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            if (item == 0) {
                Intent action = new Intent(getActivity(), UploadFilesActivity.class);
                action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, ((FileActivity) getActivity()).getAccount());
                getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_SELECT_MULTIPLE_FILES);

            } else if (item == 1) {
                Intent action = new Intent(Intent.ACTION_GET_CONTENT);
                action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
                //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                    action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                }//from   ww w  . j  a v a  2s  . c  o  m
                getActivity().startActivityForResult(
                        Intent.createChooser(action, getString(R.string.upload_chooser_title)),
                        FileDisplayActivity.ACTION_SELECT_CONTENT_FROM_APPS);
            }
        }
    });
    return builder.create();
}

From source file:net.i2p.android.wizard.ui.I2PB64DestinationFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_wizard_page_single_text_field_picker, container, false);
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());
    ((TextView) rootView.findViewById(R.id.wizard_text_field_desc)).setText(mPage.getDesc());

    Button b = (Button) rootView.findViewById(R.id.wizard_text_field_pick);
    b.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.setType("text/plain");
            i.addCategory(Intent.CATEGORY_OPENABLE);
            try {
                startActivityForResult(Intent.createChooser(i, "Select B64 file"), REQUEST_DESTINATION_FILE);
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(getActivity(), "Please install a File Manager.", Toast.LENGTH_SHORT).show();
            }//  w  w  w.j a  v a 2s . co  m
        }
    });

    mFieldView = ((TextView) rootView.findViewById(R.id.wizard_text_field));
    mFieldView.setHint(mPage.getTitle());
    if (mPage.getData().getString(Page.SIMPLE_DATA_KEY) != null)
        mFieldView.setText(mPage.getData().getString(Page.SIMPLE_DATA_KEY));
    else if (mPage.getDefault() != null) {
        mFieldView.setText(mPage.getDefault());
        mPage.getData().putString(Page.SIMPLE_DATA_KEY, mPage.getDefault());
    }

    mFeedbackView = (TextView) rootView.findViewById(R.id.wizard_text_field_feedback);

    return rootView;
}

From source file:com.waz.zclient.pages.main.conversation.AssetIntentsManager.java

private void openDocument(String mimeType, IntentType tpe) {
    if (BuildConfig.IS_TEST_GALLERY_ALLOWED) {
        // trying to load file from testing gallery,
        // this is needed because we are not able to override DocumentsUI on some android versions.
        Intent intent = new Intent("com.wire.testing.GET_DOCUMENT").setType(mimeType);
        if (!pm.queryIntentActivities(intent, PackageManager.MATCH_ALL).isEmpty()) {
            callback.openIntent(intent, tpe);
            return;
        }// w  ww .jav a2s  .  c  om
        Timber.i("Did not resolve testing gallery for intent: %s", intent.toString());
    }
    callback.openIntent(
            new Intent(openDocumentAction()).setType(mimeType).addCategory(Intent.CATEGORY_OPENABLE), tpe);
}

From source file:com.cerema.cloud2.ui.dialog.UploadSourceDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    String[] allTheItems = { getString(R.string.actionbar_upload_files),
            getString(R.string.actionbar_upload_from_apps) };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.actionbar_upload);
    builder.setItems(allTheItems, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            if (item == 0) {
                Intent action = new Intent(getActivity(), UploadFilesActivity.class);
                action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, ((FileActivity) getActivity()).getAccount());
                //startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
                // this flow seems broken;
                // Actionbarsherlock, maybe?
                getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_SELECT_MULTIPLE_FILES);

            } else if (item == 1) {
                Intent action = new Intent(Intent.ACTION_GET_CONTENT);
                action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
                //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                    action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                }//from   w w  w  .  j a  v a2  s  .  c o  m
                getActivity().startActivityForResult(
                        Intent.createChooser(action, getString(R.string.upload_chooser_title)),
                        FileDisplayActivity.ACTION_SELECT_CONTENT_FROM_APPS);
            }
        }
    });
    return builder.create();
}

From source file:com.magizdev.babyoneday.profilewizard.AvatarFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(com.magizdev.babyoneday.R.layout.fragment_profilewizard_avatar, container,
            false);/*w w  w.j av  a 2  s  . c o  m*/
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());

    mAvatarBtn = (ImageButton) rootView.findViewById(com.magizdev.babyoneday.R.id.profile_pic);
    Bitmap avatar = (Bitmap) mPage.getData().getParcelable(Profile.AVATAR);
    if (avatar != null) {
        mAvatarBtn.setBackgroundDrawable(new BitmapDrawable(avatar));
    }
    mAvatarBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
            galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
            galleryIntent.setType("image/*");
            startActivityForResult(galleryIntent, IMAGE_REQUEST_CODE);
        }
    });
    return rootView;
}