Android - Why my saved image is not appearing in the default gallery of my phone?

前端 未结 5 989
时光说笑
时光说笑 2021-01-14 01:44

I am trying to save an image from my application to the default gallery of my phone. The code below works perfectly if I have a SD card on the phone. The image saved appears

5条回答
  •  一个人的身影
    2021-01-14 02:13

    Copy Past this Function in your Activity

    private void scanner(String path) {
    
            MediaScannerConnection.scanFile(FrameActivity.this,
                    new String[] { path }, null,
                    new MediaScannerConnection.OnScanCompletedListener() {
    
                        public void onScanCompleted(String path, Uri uri) {
                            Log.i("TAG", "Finished scanning " + path);
                        }
                    });
        }
    

    And then add this Line where you save your image

    scanner(imageFile.getAbsolutePath());
    

提交回复
热议问题