Android How to use MediaScannerConnection scanFile

前端 未结 8 1801
醉梦人生
醉梦人生 2020-11-22 07:20

Im adding images to a folder on the SDCARD. Since the images and my folder is not immediately visible in the Gallery im trying to get the MediaScannerConnection to update an

8条回答
  •  庸人自扰
    2020-11-22 07:37

    I was looking for the same thing and I found this in the ApiDemos, ExternalStorage. Solved all my problems as it scans a single file.

     MediaScannerConnection.scanFile(this,
              new String[] { file.toString() }, null,
              new MediaScannerConnection.OnScanCompletedListener() {
          public void onScanCompleted(String path, Uri uri) {
              Log.i("ExternalStorage", "Scanned " + path + ":");
              Log.i("ExternalStorage", "-> uri=" + uri);
          }
     });
    

提交回复
热议问题