0

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);'

Bharat Sonawane
  • 162
  • 3
  • 10
  • Possible duplicate of [Open gallery app from Android Intent](http://stackoverflow.com/questions/16928727/open-gallery-app-from-android-intent) – Maksim Ostrovidov Nov 07 '16 at 11:15
  • @maxost No, I want to open directly inbuilt gallery app of phone not any other app like photos. – Bharat Sonawane Nov 07 '16 at 11:45
  • 2
    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 Nov 07 '16 at 12:25

3 Answers3

0

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" />

Sampad
  • 1,645
  • 11
  • 14
0

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"/>
Kinjal
  • 1,195
  • 4
  • 13
  • 24
0

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;
    }
priyanka kataria
  • 417
  • 5
  • 17
  • not working.No error but it shows file chooser...i dont want that.on button click it should land directly in gallery – Bharat Sonawane Nov 07 '16 at 11:48
  • 1
    You should be aware that Gallery no longer exists on some devices running Lollipop and above android versions. The photos app is the replacement that is why we are now using file chooser.But if you still needs to open direct gallery You can use this:- Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivity(galleryIntent); – priyanka kataria Nov 07 '16 at 12:05