Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 334 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'ACTION_MEDIA_SCANNER_SCAN_FILE:String' is deprecated

#1
activity?.sendBroadcast(Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(copyFile)))

I got the warning

> ACTION_MEDIA_SCANNER_SCAN_FILE is deprecated.

in above code

Is there a simple replacement code?
Reply

#2
From

[To see links please register here]

> This constant was deprecated in API level 29. Callers should migrate to inserting items directly into MediaStore, where they will be automatically scanned after each mutation

Reply

#3
ACTION_MEDIA_SCANNER_SCAN_FILE Deprecated!

You can use the following

Java

File file = new File(filePath);
MediaScannerConnection.scanFile(context,
new String[]{file.toString()},
null, null);

Kotlin

val file = File(filePath)
MediaScannerConnection.scanFile(context, arrayOf(file.toString()),
null, null)

This will request the media scanner to scan the files at the specified path. Also, it is worth noticing that 3rd and 4th param in scanFile() method is null in the above example. However the third param can be used to optionally specify the MIME TYPE of the file and the fourth param can be used to supply a listener to listen to the scan completion event.

[Refer developer site for details][1]


[1]:

[To see links please register here]


Following is the deprecated way

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));

Reply

#4
If you're using the Media Store API passing it to the resolver will already trigger a media scan. Here an example for an image:

val contentValues = ContentValues().apply {
put(MediaStore.MediaColumns.DISPLAY_NAME, "test.jpg")
put(MediaStore.MediaColumns.MIME_TYPE, "image/jpg")
put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_PICTURES) // requires API level 29
}


// this also adds it to the gallery
contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through