Android - Image Picker, Wrong Image

后端 未结 5 1126
情书的邮戳
情书的邮戳 2021-02-19 05:12

I am starting a request for an image pick:

Intent intent = new Intent();
intent.setType( \"image/*\" );
intent.setAction( Intent.ACTION_GET_CONTENT );
startActiv         


        
5条回答
  •  無奈伤痛
    2021-02-19 05:42

    try this one

     //Put this code on some event 
    
       Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    
     startActivityForResult(intent, REQUEST_CODE);
    
               // When above event fire then its comes to this 
            @Override
            protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                super.onActivityResult(requestCode, resultCode, data);
                  if (resultCode==RESULT_OK && requestCode==1){
    
                      Uri selectedImage = data.getData();
                        String[] filePathColumn = { MediaStore.Images.Media.DATA };
    
                        Cursor cursor = getContentResolver().query(selectedImage,
                                filePathColumn, null, null, null);
                        cursor.moveToFirst();
                        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                        filePath = cursor.getString(columnIndex);
                        cursor.close();
    
                                // Use it as per recruitment 
                        actualBitmap =BitmapFactory.decodeFile(filePath);
    
                  }
        }
    

提交回复
热议问题