Can I open the gallery using Intent?

    2 answers 2

    The question is asked too broadly. Alternatively, you can:

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivityForResult(intent, SOME_CODE); 
    • Just open the gallery where photos and pictures are stored, without any further action on the selected picture. About SOME_CODE climbed on sites, not met. Thanks, I will understand further. - curumb
    • SOME_CODE is just a certain number that will be returned from the Activity when the user selects a picture in the gallery. - Hi

    Create an arbitrary function for example

     public void openfile(View v) throws Exception { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivityForResult(intent, OPEN_FILE); } 

    OPEN_FILE is a constant that can be globally declared before

     @Override public void onCreate.... private static final int OPEN_FILE = 300; 

    Then in the onActivityResult method:

     protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if(requestCode == OPEN_FILE){ //выбрали рисунок из галерееи Uri ChossefileUri = data.getData(); if(ChossefileUri !=null){ fileUri = ChossefileUri; if(fileUri != null) { //тут уже работейте с fileUri вашего файла } } } } 
    • @Alexander Tutkevich; To format a code, select it with the mouse and press the {} button of the editor. - Deleted