Android SD card created file not visible

后端 未结 2 1457
面向向阳花
面向向阳花 2021-01-21 15:44

I\'ve created a file in the SD card using the code below:

File outputFile = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + File.separato         


        
2条回答
  •  生来不讨喜
    2021-01-21 16:16

    image files need to be explicitly indexed in order to appear in the gallery. I suppose other applications may be using the same mechanism to get the thumbnail. Here is some code that will scan a new media file, right after you wrote it:

     Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
     Uri uri = Uri.fromFile(outputFile);
     intent.setData(uri);
     sendBroadcast(intent);
    

提交回复
热议问题