Example usage for android.content Intent ACTION_GET_CONTENT

List of usage examples for android.content Intent ACTION_GET_CONTENT

Introduction

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

Prototype

String ACTION_GET_CONTENT

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

Click Source Link

Document

Activity Action: Allow the user to select a particular kind of data and return it.

Usage

From source file:com.renard.ocr.BaseDocumentActivitiy.java

protected void startGallery() {
    cameraPicUri = null;// w w  w  .  j  av  a  2s . c o  m
    Intent i = new Intent(Intent.ACTION_GET_CONTENT, null);
    if (Build.VERSION.SDK_INT >= 19) {
        i.setType("image/*");
        i.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "image/png", "image/jpg", "image/jpeg" });
    } else {
        i.setType("image/png,image/jpg, image/jpeg");
    }

    Intent chooser = Intent.createChooser(i, getString(R.string.image_source));
    startActivityForResult(chooser, REQUEST_CODE_PICK_PHOTO);
}

From source file:mobisocial.bento.anyshare.ui.FeedItemListActivity.java

private void goSelection() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, REQUEST_PICK);
}

From source file:com.game.simple.Game3.java

public static void openImage() {
    //---timer---//
    //StartReConnect();
    //-----------//
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.putExtra("return-data", true);
    self.startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);
}

From source file:httbdd.cse.nghiatran.halofind.screen.MainActivity.java

private void pickFromGallery() {
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(Intent.createChooser(intent, getString(R.string.label_select_picture)),
            REQUEST_SELECT_PICTURE);//from   w  ww .ja v a  2 s .c  o  m
}

From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java

public Drawer(MainActivity mainActivity) {
    this.mainActivity = mainActivity;
    resources = mainActivity.getResources();
    dataUtils = DataUtils.getInstance();

    drawerHeaderLayout = mainActivity.getLayoutInflater().inflate(R.layout.drawerheader, null);
    drawerHeaderParent = drawerHeaderLayout.findViewById(R.id.drawer_header_parent);
    drawerHeaderView = drawerHeaderLayout.findViewById(R.id.drawer_header);
    drawerHeaderView.setOnLongClickListener(v -> {
        Intent intent1;//from w w w. j  ava2s  .  c  om
        if (SDK_INT < Build.VERSION_CODES.KITKAT) {
            intent1 = new Intent();
            intent1.setAction(Intent.ACTION_GET_CONTENT);
        } else {
            intent1 = new Intent(Intent.ACTION_OPEN_DOCUMENT);

        }
        intent1.addCategory(Intent.CATEGORY_OPENABLE);
        intent1.setType("image/*");
        mainActivity.startActivityForResult(intent1, image_selector_request_code);
        return false;
    });

    mImageLoader = AppConfig.getInstance().getImageLoader();

    navView = mainActivity.findViewById(R.id.navigation);

    //set width of drawer in portrait to follow material guidelines
    /*if(!Utils.isDeviceInLandScape(mainActivity)){
    setNavViewDimension(navView);
    }*/

    navView.setNavigationItemSelectedListener(this);

    int accentColor = mainActivity.getAccent(), idleColor;

    if (mainActivity.getAppTheme().equals(AppTheme.LIGHT)) {
        idleColor = mainActivity.getResources().getColor(R.color.item_light_theme);
    } else {
        idleColor = Color.WHITE;
    }

    actionViewStateManager = new ActionViewStateManager(navView, idleColor, accentColor);

    ColorStateList drawerColors = new ColorStateList(
            new int[][] { new int[] { android.R.attr.state_checked },
                    new int[] { android.R.attr.state_enabled }, new int[] { android.R.attr.state_pressed },
                    new int[] { android.R.attr.state_focused }, new int[] { android.R.attr.state_pressed } },
            new int[] { accentColor, idleColor, idleColor, idleColor, idleColor });

    navView.setItemTextColor(drawerColors);
    navView.setItemIconTintList(drawerColors);

    if (mainActivity.getAppTheme().equals(AppTheme.DARK)) {
        navView.setBackgroundColor(Utils.getColor(mainActivity, R.color.holo_dark_background));
    } else if (mainActivity.getAppTheme().equals(AppTheme.BLACK)) {
        navView.setBackgroundColor(Utils.getColor(mainActivity, android.R.color.black));
    } else {
        navView.setBackgroundColor(Color.WHITE);
    }

    mDrawerLayout = mainActivity.findViewById(R.id.drawer_layout);
    //mDrawerLayout.setStatusBarBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
    drawerHeaderView.setBackgroundResource(R.drawable.amaze_header);
    //drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
    if (mainActivity.findViewById(R.id.tab_frame) != null) {
        lock(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
        open();
        mDrawerLayout.setScrimColor(Color.TRANSPARENT);
        mDrawerLayout.post(this::open);
    } else if (mainActivity.findViewById(R.id.tab_frame) == null) {
        unlock();
        close();
        mDrawerLayout.post(this::close);
    }
    navView.addHeaderView(drawerHeaderLayout);

    if (!isDrawerLocked) {
        mDrawerToggle = new ActionBarDrawerToggle(mainActivity, /* host Activity */
                mDrawerLayout, /* DrawerLayout object */
                R.drawable.ic_drawer_l, /* nav drawer image to replace 'Up' caret */
                R.string.drawer_open, /* "open drawer" description for accessibility */
                R.string.drawer_close /* "close drawer" description for accessibility */
        ) {
            public void onDrawerClosed(View view) {
                Drawer.this.onDrawerClosed();
            }

            public void onDrawerOpened(View drawerView) {
                //title.setText("Amaze File Manager");
                // creates call to onPrepareOptionsMenu()
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        mainActivity.getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_drawer_l);
        mainActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        mainActivity.getSupportActionBar().setHomeButtonEnabled(true);
        mDrawerToggle.syncState();
    }

}

From source file:at.tomtasche.reader.ui.activity.MainActivity.java

public void findDocument() {

    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    // remove mime-type because most apps don't support ODF mime-types
    intent.setType("application/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    PackageManager pm = getPackageManager();
    final List<ResolveInfo> targets = pm.queryIntentActivities(intent, 0);
    int size = targets.size();
    String[] targetNames = new String[size];
    for (int i = 0; i < size; i++) {
        targetNames[i] = targets.get(i).loadLabel(pm).toString();
    }//w  w w . jav  a2s . com

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.dialog_choose_filemanager);
    builder.setItems(targetNames, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            ResolveInfo target = targets.get(which);
            if (target == null) {
                return;
            }

            intent.setComponent(new ComponentName(target.activityInfo.packageName, target.activityInfo.name));

            try {
                startActivityForResult(intent, 42);
            } catch (Exception e) {
                e.printStackTrace();

                showCrouton(R.string.crouton_error_open_app, new Runnable() {

                    @Override
                    public void run() {
                        findDocument();
                    }
                }, AppMsg.STYLE_ALERT);
            }

            dialog.dismiss();
        }
    });
    builder.show();
}

From source file:com.example.android.CreateNewPlayer.java

/** Called when the user clicks the Choose Image button */
public void pickImage(View View) {
    playButton();/*from   w  ww .jav  a  2s  .c  o  m*/
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, REQUEST_CODE);
}

From source file:com.truemind.selidpic_v20.ui.GalleryActivity.java

/**
 * Android 6.0??? ??  ? /*from www .ja  v  a2  s.  c  om*/
 *  Permission ?  ? ?? ?
 * */
@TargetApi(Build.VERSION_CODES.M)
private void checkPermission() {
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        /** Access denied (Permission denied)*/

        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.READ_EXTERNAL_STORAGE)) {
            //??    -  ? ?? ? ?  ? ?  .
            //??? '  ' ? ?? ?.
            Log.d(TAG, "??  .");
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                    MY_PERMISSION_REQUEST_STORAGE);

        } else {
            Log.d(TAG, " ? .");
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                    MY_PERMISSION_REQUEST_STORAGE);
        }
    } else {
        /** Access already granted (Permission granted)*/

        Log.d(TAG, "Permission is granted");
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
    }
}

From source file:com.duy.pascal.ui.editor.EditorDelegate.java

private void selectMediaUrl() {
    Intent i = new Intent();
    i.setType("audio/*");
    i.setAction(Intent.ACTION_GET_CONTENT);
    Intent intent = Intent.createChooser(i, "Complete action using");
    mActivity.startActivityForResult(intent, EditorActivity.ACTION_PICK_MEDIA_URL);
}

From source file:com.Jsu.framework.image.imageChooser.ImageChooserManager.java

private void choosePicture() throws ChooserException {
    checkDirectory();/*from  w w w  . java2 s  .co  m*/
    try {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
        //            intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        if (extras != null) {
            intent.putExtras(extras);
        }
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        throw new ChooserException(e);
    }
}