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.avalond.ad_blocak.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    switch (item.getItemId()) {
    case R.id.action_restore:
        config = FileHelper.loadPreviousSettings(this);
        FileHelper.writeSettings(this, MainActivity.config);
        reload();/*from www.jav a  2s . com*/
        break;
    case R.id.action_refresh:
        refresh();
        break;
    case R.id.action_load_defaults:
        config = FileHelper.loadDefaultSettings(this);
        reload();
        FileHelper.writeSettings(this, MainActivity.config);
        break;
    case R.id.action_import:
        Intent intent = new Intent().setType("*/*").setAction(Intent.ACTION_OPEN_DOCUMENT)
                .addCategory(Intent.CATEGORY_OPENABLE);

        startActivityForResult(intent, REQUEST_FILE_OPEN);
        break;
    case R.id.action_export:
        Intent exportIntent = new Intent(Intent.ACTION_CREATE_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
                .setType("*/*").putExtra(Intent.EXTRA_TITLE, "dns66.json");

        startActivityForResult(exportIntent, REQUEST_FILE_STORE);
        break;
    case R.id.action_about:
        Intent infoIntent = new Intent(this, InfoActivity.class);
        startActivity(infoIntent);
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.uphyca.kitkat.storage.ui.MainFragment.java

/**
 * ??/*from  ww  w .j a  va2 s.  co m*/
 */
@OnClick(R.id.button_create)
void onCreateButtonClick() {
    String fileName = String.format("document-%d.txt", new SecureRandom().nextInt());
    Intent intent = new Intent().setAction(Intent.ACTION_CREATE_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
            .setType("text/plain").putExtra(Intent.EXTRA_TITLE, fileName);
    startActivityForResult(intent, REQUEST_CREATE);
}

From source file:com.chess.genesis.activity.GameListLocalFrag.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.new_game:
        new NewLocalGameDialog(act, handle).show();
        break;//from w w w.  jav  a 2  s .  c om
    case R.id.import_game:
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent = intent.addCategory(Intent.CATEGORY_OPENABLE).setType("text/*");
        intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
        try {
            startActivityForResult(intent, Enums.IMPORT_GAME);
        } catch (final ActivityNotFoundException e) {
            Toast.makeText(act, "No File Manager Installed", Toast.LENGTH_LONG).show();
        }
        break;
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:org.jak_linux.dns66.MainActivity.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    switch (item.getItemId()) {
    case R.id.action_restore:
        config = FileHelper.loadPreviousSettings(this);
        FileHelper.writeSettings(this, MainActivity.config);
        reload();/*  w w  w .  jav a  2  s  . c o m*/
        break;
    case R.id.action_refresh:
        refresh();
        break;
    case R.id.action_load_defaults:
        config = FileHelper.loadDefaultSettings(this);
        reload();
        FileHelper.writeSettings(this, MainActivity.config);
        break;
    case R.id.action_import:
        Intent intent = new Intent().setType("*/*").setAction(Intent.ACTION_OPEN_DOCUMENT)
                .addCategory(Intent.CATEGORY_OPENABLE);

        startActivityForResult(intent, REQUEST_FILE_OPEN);
        break;
    case R.id.action_export:
        Intent exportIntent = new Intent(Intent.ACTION_CREATE_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
                .setType("*/*").putExtra(Intent.EXTRA_TITLE, "dns66.json");

        startActivityForResult(exportIntent, REQUEST_FILE_STORE);
        break;
    case R.id.setting_show_notification:
        // If we are enabling notifications, we do not need to show a dialog.
        if (!item.isChecked()) {
            item.setChecked(!item.isChecked());
            MainActivity.config.showNotification = item.isChecked();
            FileHelper.writeSettings(MainActivity.this, MainActivity.config);
            break;
        }
        new AlertDialog.Builder(this).setIcon(R.drawable.ic_warning)
                .setTitle(R.string.disable_notification_title).setMessage(R.string.disable_notification_message)
                .setPositiveButton(R.string.disable_notification_ack, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        item.setChecked(!item.isChecked());
                        MainActivity.config.showNotification = item.isChecked();
                        FileHelper.writeSettings(MainActivity.this, MainActivity.config);
                    }
                }).setNegativeButton(R.string.disable_notification_nak, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                }).show();
        break;
    case R.id.action_about:
        Intent infoIntent = new Intent(this, InfoActivity.class);
        startActivity(infoIntent);
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.stephenmcgruer.threethingstoday.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.mi_export_database:
        new DatabaseExportTask(this, mThreeThingsDatabase).execute();
        return true;
    case R.id.mi_import_database:
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        try {/* w  ww . j  a  va2 s  .  c  o m*/
            startActivityForResult(Intent.createChooser(intent, "Select a file to open"), DATABASE_IMPORT_CODE);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(getApplicationContext(), "Please install a File Manager", Toast.LENGTH_LONG).show();
        }
        return true;
    case R.id.mi_sign_in_sign_out:
        if (FirebaseAuth.getInstance().getCurrentUser() == null) {
            Intent signInIntent = AuthUI.getInstance().createSignInIntentBuilder()
                    .setProviders(Arrays.asList(new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()))
                    .build();
            startActivityForResult(signInIntent, FIREBASE_SIGN_IN_CODE);
        } else {
            FirebaseAuth.getInstance().signOut();
            Toast.makeText(this, "Signed out", Toast.LENGTH_SHORT).show();
        }
        return true;
    case R.id.mi_test_notification:
        Intent notificationIntent = new Intent(this, NotificationIntentService.class);
        startService(notificationIntent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:cc.metapro.openct.allclasses.ExcelDialog.java

private void showFilerChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    try {// ww  w.j  a  v  a 2  s .co m
        startActivityForResult(Intent.createChooser(intent, getString(R.string.select_schedule_file)),
                FILE_SELECT_CODE);
    } catch (ActivityNotFoundException ex) {
        Toast.makeText(getActivity(), R.string.fail_file_chooser, Toast.LENGTH_LONG).show();
    }
}

From source file:com.uphyca.kitkat.storage.ui.MainFragment.java

/**
 * ?//w  ww .  j ava  2  s  .  c o  m
 */
@OnClick(R.id.button_edit)
void onEditButtonClick() {
    Intent intent = new Intent().setAction(Intent.ACTION_OPEN_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
            .setType("text/plain");
    startActivityForResult(intent, REQUEST_EDIT);
}

From source file:com.phonegap.CameraLauncher.java

/**
 * Get image from photo library.//from   www  . java 2 s  . com
 * 
 * @param quality         Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param srcType         The album to get image from.
 * @param returnType      Set the type of image to return. 
 */
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
public void getImage(int quality, int srcType, int returnType) {
    this.mQuality = quality;

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    this.ctx.startActivityForResult((Plugin) this, Intent.createChooser(intent, new String("Get Picture")),
            (srcType + 1) * 16 + returnType + 1);
}

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

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mRoots = DocumentsApplication.getRootsCache(this);

    virtualIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    virtualIntent.addCategory(Intent.CATEGORY_OPENABLE);
    virtualIntent.setType("*/*");
    virtualIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

    setResult(Activity.RESULT_CANCELED);
    setContentView(R.layout.activity);//from  w  ww  . j  a va  2s.c  o  m

    final Resources res = getResources();
    mShowAsDialog = res.getBoolean(R.bool.show_as_dialog);

    if (mShowAsDialog) {
        // backgroundDimAmount from theme isn't applied; do it manually
        final WindowManager.LayoutParams a = getWindow().getAttributes();
        a.dimAmount = 0.6f;
        getWindow().setAttributes(a);

        getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        // Inset ourselves to look like a dialog
        final Point size = new Point();
        getWindowManager().getDefaultDisplay().getSize(size);

        final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x);
        final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y);
        final int insetX = (size.x - width) / 2;
        final int insetY = (size.y - height) / 2;

        final Drawable before = getWindow().getDecorView().getBackground();
        final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY);
        getWindow().getDecorView().setBackground(after);

        // Dismiss when touch down in the dimmed inset area
        getWindow().getDecorView().setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    final float x = event.getX();
                    final float y = event.getY();
                    if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) {
                        finish();
                        return true;
                    }
                }
                return false;
            }
        });

    } else {
        // Non-dialog means we have a drawer
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph,
                R.string.drawer_open, R.string.drawer_close);

        mDrawerLayout.setDrawerListener(mDrawerListener);
        mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START);

        mRootsContainer = findViewById(R.id.container_roots);
    }

    mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);

    if (icicle != null) {
        mState = icicle.getParcelable(EXTRA_STATE);
    } else {
        if (DEBUG) {
            Log.i(TAG, "mState");
        }
        buildDefaultState();
    }

    // Hide roots when we're managing a specific root
    if (mState.action == ACTION_MANAGE) {
        if (mShowAsDialog) {
            findViewById(R.id.dialog_roots).setVisibility(View.GONE);
        } else {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        }
    }

    if (mState.action == ACTION_CREATE) {
        final String mimeType = virtualIntent.getType();
        final String title = virtualIntent.getStringExtra(Intent.EXTRA_TITLE);
        SaveFragment.show(getFragmentManager(), mimeType, title);
    }

    if (mState.action == ACTION_GET_CONTENT) {
        final Intent moreApps = new Intent(virtualIntent);
        moreApps.setComponent(null);
        moreApps.setPackage(null);
        RootsFragment.show(getFragmentManager(), moreApps);
    } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) {
        RootsFragment.show(getFragmentManager(), null);
    }

    if (!mState.restored) {
        if (mState.action == ACTION_MANAGE) {
            final Uri rootUri = virtualIntent.getData();
            new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor());
        } else {
            new RestoreStackTask().execute();
        }
    } else {
        onCurrentDirectoryChanged(ANIM_NONE);
    }
}

From source file:com.mifos.mifosxdroid.dialogfragments.DocumentDialogFragment.java

@OnClick(R.id.tv_choose_file)
public void openFilePicker() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {/*from   w w  w. jav a  2  s . c  o m*/
        startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
        // Potentially direct the user to the Market with a Dialog
        Toast.makeText(getActivity(), "Please install a File Manager.", Toast.LENGTH_SHORT).show();
    }
}