Open gallery app from Android Intent

后端 未结 6 1192
难免孤独
难免孤独 2020-11-29 04:30

I\'m looking for a way to open the Android gallery application from an intent.

I do not want to return a picture, but rather just open the gallery to al

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 05:14

    if somebody still getting the error, even after adding the following code

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

    then you might be opening the intent in another class (by calling) due to this the app will crash when you click the button.

    SOLUTION FOR THE PROBLEM

    Put intent in the class file which is connected to the button's layout file. for example- activity_main.xml contains the button and it is connected to MainActivity.java file. but due to fragmentation, you are defining the intent in some other class(lets says Activity.java) then your app will crash unless you place the intent in MainActivity.java file. I was getting this error and it is resolved by this.

提交回复
热议问题