Open Gallery App in Android

后端 未结 3 1059
说谎
说谎 2021-02-03 13:30

I am trying to open inbuilt gallery app pressing a button in my app.

I am trying out on Android 2.3 and above phones. The phones/tablet that I have are

Samsung

相关标签:
3条回答
  • 2021-02-03 13:46

    I figured out the way..

     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
     "content://media/internal/images/media")); 
     startActivity(intent); 
    

    This piece of code just opened the gallery without any issues. Could get it working on all versions!

    Thought to put it as answer for people who are looking to open a Gallery on all versions.

    Thanks Guys! :)

    0 讨论(0)
  • 2021-02-03 13:48

    Try This out

    btnGallery.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, ""), PICK_IMAGE);
        }
    });
    

    UPDATE onActivityResult

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != Activity.RESULT_CANCELED) {
            if (requestCode == PICK_IMAGE) {
                Uri selectedImageUri = data.getData();
            } 
        }
    }
    

    UPDATE TO OPEN GALLERY APP

    Intent galleryIntent = new Intent(Intent.ACTION_VIEW, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivity(galleryIntent);
    
    0 讨论(0)
  • 2021-02-03 14:10
    Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(
                        Intent.createChooser(intent, "Complete action using"),
                        PICK_FROM_FILE);
    
    0 讨论(0)
提交回复
热议问题