0
votes

In my application I am trying to open only default built in gallery app not even photos app and other file explorer apps. On button click it will directly land in gallery,How can I do this?

My Code 'Intent intent = new Intent(Intent.ACTION_PICK); intent.setType("image/*"); startActivityForResult(intent,PICK_IMAGE);'

3
@maxost No, I want to open directly inbuilt gallery app of phone not any other app like photos. - Bharat Sonawane
There are ~2 billion Android devices, made up of thousands of device models from hundreds of manufacturers. None have to have a "default built in gallery". Those that do will have different ones, as manufacturers usually ship their own custom "built in gallery". There is no guaranteed way to identify such an app, let alone launch it. - CommonsWare

3 Answers

0
votes

Try Like this

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);//
    startActivityForResult(Intent.createChooser(intent, "Select Picture"),PICK_IMAGE);

OnActivityResult for get image

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PICK_IMAGE)
    {
        if (resultCode == Activity.RESULT_OK)
        {
            if (data != null)
            {
                try
                {

                    Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), data.getData());

                } catch (IOException e)
                {
                    e.printStackTrace();
                }

            }
        } else if (resultCode == Activity.RESULT_CANCELED)
        {
            Toast.makeText(getActivity(), "Cancelled", Toast.LENGTH_SHORT).show();
        }
    } }

Add permissions in Manifest File

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"  />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
0
votes

Try this one...

 private int PICK_IMAGE_REQUEST = 1;

tvGallery.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent();
                    // Show only images, no videos or anything else
                    intent.setType("image/*");
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    // Always show the chooser (if there are multiple options available)
                    startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);


                }
            });

Use Permission in Android Manifest File

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

0
votes

Try this:-

public static final int GALLERY_PICTURE = 1;
private String selectedImagePath = null;

Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, "Select File"), GALLERY_PICTURE);

onActivityResult()  :-

if (requestCode == GALLERY_PICTURE && resultCode == RESULT_OK) {
            selectedImagePath = getRealPathFromURI_API19(this, data.getData());
            Log.e("gallery path", selectedImagePath);  
        }


@SuppressLint("NewApi")
    public static String getRealPathFromURI_API19(Context context, Uri uri) {
        String filePath = "";
        String wholeID = DocumentsContract.getDocumentId(uri);
        String id = wholeID.split(":")[1];
        String[] column = {MediaStore.Images.Media.DATA};
        String sel = MediaStore.Images.Media._ID + "=?";
        Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                column, sel, new String[]{id}, null);
        int columnIndex = cursor.getColumnIndex(column[0]);
        if (cursor.moveToFirst()) {
            filePath = cursor.getString(columnIndex);
        }
        cursor.close();
        return filePath;
    }