How to invoke Android media scanner for vendor provided external SD card, not the one obtained via getExternalStorage()

前端 未结 2 1967
面向向阳花
面向向阳花 2020-12-21 07:23

My app allows user to save files on an external SD card besides the getExternalStorage() path. I understand that Android does not have notion of external SD cardas such but

2条回答
  •  情深已故
    2020-12-21 08:13

    For Api 8 and above you can use this

     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);
      }
     });
    

    This scans only an individual file and you can give any path here, including alternative external storage.

提交回复
热议问题