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:com.renard.ocr.documents.creation.NewDocumentActivity.java

protected void startGallery() {
    mAnalytics.startGallery();/*from   w  ww  .ja va  2s.  co  m*/
    cameraPicUri = null;
    Intent i;
    if (Build.VERSION.SDK_INT >= 19) {
        i = new Intent(Intent.ACTION_GET_CONTENT, null);
        i.addCategory(Intent.CATEGORY_OPENABLE);
        i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        i.setType("image/*");
        i.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "image/png", "image/jpg", "image/jpeg" });
    } else {
        i = new Intent(Intent.ACTION_GET_CONTENT, null);
        i.setType("image/png,image/jpg, image/jpeg");
    }

    Intent chooser = Intent.createChooser(i, getString(R.string.image_source));
    try {
        startActivityForResult(chooser, REQUEST_CODE_PICK_PHOTO);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, R.string.no_gallery_found, Toast.LENGTH_LONG).show();
    }
}

From source file:com.survivingwithandroid.pegboard.DreamPinsActivity.java

public void onBackgroundSelected() {
    LayoutInflater inf = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inf.inflate(R.layout.popbkg_layout, null, false);

    final PopupWindow pw = new PopupWindow(v);
    pw.setFocusable(true);/*from  ww  w . jav a  2  s.com*/
    pw.setWidth(RelativeLayout.LayoutParams.WRAP_CONTENT);
    pw.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);

    TextView changeTxt = (TextView) v.findViewById(R.id.dlgChange);
    TextView resetTxt = (TextView) v.findViewById(R.id.dlgReset);
    TextView cancelTxt = (TextView) v.findViewById(R.id.dlgCancel);
    cancelTxt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            pw.dismiss();
        }
    });

    resetTxt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            pw.dismiss();
            pinTableFrag.setBackground(R.drawable.tilebkg);
        }
    });

    changeTxt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            pw.dismiss();
            // Start a new Intent to get the picture from the Gallery
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            startActivityForResult(intent, SELECT_PICTURE);
        }
    });

    pw.showAtLocation(v, Gravity.CENTER, 0, 0);

}

From source file:eu.alefzero.owncloud.ui.activity.FileDisplayActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean retval = true;
    switch (item.getItemId()) {
    case R.id.createDirectoryItem: {
        showDialog(DIALOG_CREATE_DIR);/*from   w ww.j  ava 2 s. co m*/
        break;
    }
    case R.id.startSync: {
        ContentResolver.cancelSync(null, "org.owncloud"); // cancel the current synchronizations of any ownCloud account
        Bundle bundle = new Bundle();
        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        ContentResolver.requestSync(AccountUtils.getCurrentOwnCloudAccount(this), "org.owncloud", bundle);
        break;
    }
    case R.id.action_upload: {
        Intent action = new Intent(Intent.ACTION_GET_CONTENT);
        action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
        startActivityForResult(Intent.createChooser(action, "Upload file from..."), ACTION_SELECT_FILE);
        break;
    }
    case R.id.action_settings: {
        Intent settingsIntent = new Intent(this, Preferences.class);
        startActivity(settingsIntent);
        break;
    }
    case R.id.about_app: {
        showDialog(DIALOG_ABOUT_APP);
        break;
    }
    case android.R.id.home: {
        if (mCurrentDir != null && mCurrentDir.getParentId() != 0) {
            onBackPressed();
        }
        break;
    }
    default:
        retval = false;
    }
    return retval;
}

From source file:com.commonsware.android.tte.MainActivity.java

private void createDocument() {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
            .setType("text/plain");

    startActivityForResult(intent, REQUEST_CREATE);
}

From source file:org.fedorahosted.freeotp.MainActivity.java

/**
 * Fires an intent to spin up the "file chooser" UI and select an image.
 */// w w  w  .j  a v  a2 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("application/json");

    startActivityForResult(intent, READ_REQUEST_CODE);
}

From source file:com.commonsware.android.tte.MainActivity.java

private void openDocument(boolean allowMultiple) {
    Intent i = new Intent().setType("text/*").setAction(Intent.ACTION_OPEN_DOCUMENT)
            .putExtra(Intent.EXTRA_ALLOW_MULTIPLE, allowMultiple).addCategory(Intent.CATEGORY_OPENABLE);

    startActivityForResult(i, REQUEST_OPEN);
}

From source file:com.keepassdroid.fileselect.FileSelectActivity.java

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

    fileHistory = App.getFileHistory();//  www .  j a v a 2s  .co m

    if (fileHistory.hasRecentFiles()) {
        recentMode = true;
        setContentView(R.layout.file_selection);
    } else {
        setContentView(R.layout.file_selection_no_recent);
    }

    mList = (ListView) findViewById(R.id.file_list);

    mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            onListItemClick((ListView) parent, v, position, id);
        }
    });

    // Open button
    Button openButton = (Button) findViewById(R.id.open);
    openButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            String fileName = Util.getEditText(FileSelectActivity.this, R.id.file_filename);

            try {
                PasswordActivity.Launch(FileSelectActivity.this, fileName);
            } catch (ContentFileNotFoundException e) {
                Toast.makeText(FileSelectActivity.this, R.string.file_not_found_content, Toast.LENGTH_LONG)
                        .show();
            } catch (FileNotFoundException e) {
                Toast.makeText(FileSelectActivity.this, R.string.FileNotFound, Toast.LENGTH_LONG).show();
            }

        }
    });

    // Create button
    Button createButton = (Button) findViewById(R.id.create);
    createButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            String filename = Util.getEditText(FileSelectActivity.this, R.id.file_filename);

            // Make sure file name exists
            if (filename.length() == 0) {
                Toast.makeText(FileSelectActivity.this, R.string.error_filename_required, Toast.LENGTH_LONG)
                        .show();
                return;
            }

            // Try to create the file
            File file = new File(filename);
            try {
                if (file.exists()) {
                    Toast.makeText(FileSelectActivity.this, R.string.error_database_exists, Toast.LENGTH_LONG)
                            .show();
                    return;
                }
                File parent = file.getParentFile();

                if (parent == null || (parent.exists() && !parent.isDirectory())) {
                    Toast.makeText(FileSelectActivity.this, R.string.error_invalid_path, Toast.LENGTH_LONG)
                            .show();
                    return;
                }

                if (!parent.exists()) {
                    // Create parent dircetory
                    if (!parent.mkdirs()) {
                        Toast.makeText(FileSelectActivity.this, R.string.error_could_not_create_parent,
                                Toast.LENGTH_LONG).show();
                        return;

                    }
                }

                file.createNewFile();
            } catch (IOException e) {
                Toast.makeText(FileSelectActivity.this,
                        getText(R.string.error_file_not_create) + " " + e.getLocalizedMessage(),
                        Toast.LENGTH_LONG).show();
                return;
            }

            // Prep an object to collect a password once the database has
            // been created
            CollectPassword password = new CollectPassword(new LaunchGroupActivity(filename));

            // Create the new database
            CreateDB create = new CreateDB(FileSelectActivity.this, filename, password, true);
            ProgressTask createTask = new ProgressTask(FileSelectActivity.this, create,
                    R.string.progress_create);
            createTask.run();

        }

    });

    ImageButton browseButton = (ImageButton) findViewById(R.id.browse_button);
    browseButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (StorageAF.useStorageFramework(FileSelectActivity.this)) {
                Intent i = new Intent(StorageAF.ACTION_OPEN_DOCUMENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("*/*");
                i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                        | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
                startActivityForResult(i, OPEN_DOC);
            } else {
                Intent i;
                i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("*/*");

                try {
                    startActivityForResult(i, GET_CONTENT);
                } catch (ActivityNotFoundException e) {
                    lookForOpenIntentsFilePicker();
                } catch (SecurityException e) {
                    lookForOpenIntentsFilePicker();
                }
            }
        }

        private void lookForOpenIntentsFilePicker() {

            if (Interaction.isIntentAvailable(FileSelectActivity.this, Intents.OPEN_INTENTS_FILE_BROWSE)) {
                Intent i = new Intent(Intents.OPEN_INTENTS_FILE_BROWSE);
                i.setData(Uri.parse("file://" + Util.getEditText(FileSelectActivity.this, R.id.file_filename)));
                try {
                    startActivityForResult(i, FILE_BROWSE);
                } catch (ActivityNotFoundException e) {
                    showBrowserDialog();
                }

            } else {
                showBrowserDialog();
            }
        }

        private void showBrowserDialog() {
            BrowserDialog diag = new BrowserDialog(FileSelectActivity.this);
            diag.show();
        }
    });

    fillData();

    registerForContextMenu(mList);

    // Load default database
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String fileName = prefs.getString(PasswordActivity.KEY_DEFAULT_FILENAME, "");

    if (fileName.length() > 0) {
        Uri dbUri = UriUtil.parseDefaultFile(fileName);
        String scheme = dbUri.getScheme();

        if (!EmptyUtils.isNullOrEmpty(scheme) && scheme.equalsIgnoreCase("file")) {
            String path = dbUri.getPath();
            File db = new File(path);

            if (db.exists()) {
                try {
                    PasswordActivity.Launch(FileSelectActivity.this, path);
                } catch (Exception e) {
                    // Ignore exception
                }
            }
        } else {
            try {
                PasswordActivity.Launch(FileSelectActivity.this, dbUri.toString());
            } catch (Exception e) {
                // Ignore exception
            }
        }
    }
}

From source file:ca.rmen.android.poetassistant.main.reader.ReaderFragment.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private void open() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    PoemFile poemFile = mPoemPrefs.getSavedPoem();
    if (poemFile != null)
        intent.setData(poemFile.uri);/*from www . j  a v  a2s .co  m*/
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("text/plain");
    startActivityForResult(intent, ACTION_FILE_OPEN);
}

From source file:com.activiti.android.platform.provider.transfer.ContentTransferManager.java

public static final void requestCreateLocalContent(Fragment fr, String filename, String mimetype, File file) {

    if (AndroidVersion.isKitKatOrAbove()) {
        Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType(mimetype);/* w  w w.  j  a v  a2s . co m*/
        intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
        intent.putExtra(Intent.EXTRA_TITLE, filename);
        fr.startActivityForResult(intent, CREATE_REQUEST_CODE);
    } else {
        // Good question ? Send Intent ? File Picker ?
    }
}

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

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    assert fab != null;
    fab.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w  w  w .  j a  v  a  2  s. c  o  m*/
        public void onClick(final View view) {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("*/*");
            startActivityForResult(intent, REQUEST_INPUT);
        }
    });
    plaintextHeadline = findViewById(R.id.plainheadline);
    plaintextView = findViewById(R.id.plain);
    showPlaintextLayout(false);
    init();
}