What is Context.getExternalMediaDir ()?

The Javadoc example for Environment.getExternalStoragePublicDirectory () mentions Context.getExternalMediaDir() , but this method is not available in my version of the Android API and I cannot find it documented anywhere in any version. Is it a typo or something that never let go?

 void createExternalStoragePublicPicture() { // Create a path where we will place our picture in the user's // public pictures directory. Note that you should be careful about // what you place here, since the user often manages these files. For // pictures and other media owned by the application, consider // Context.getExternalMediaDir(). File path = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES); 
+4
source share
2 answers

I believe this is simply incorrectly named; I think they wanted to say " Context.getExternalFilesDir() ". It may have been a typo, or the method may have subsequently been renamed.

Based on the explanation in the comments (“images and other materials belonging to the application”), it exactly matches the value of getExternalFilesDir(String type) , which is “where the application can host the permanent files that it owns”. Note that you can pass null to getExternalFilesDir , which returns the root directory or is specified to return the type of folder you are looking for.

I will say: here I reflect. However, this is apparently the most likely explanation for this seemingly nonexistent method.

+5
source

No, this is not a typo (more), this is a new method on Android L Preview

Mostly geniuses on google, put the ".nomedia" file in the / Android / data / folder, and this makes an attempt to use the scanFile () MediaScannerConnection method in your folder. Therefore, if you have an application that creates or downloads media, you are probably doing acrobatics right now to scan this media and make it available to your provider if you don’t have a new API that we don’t have, because each other the phone has a much older android ...

Now our workaround was to independently scan the files and paste them into the content providers that match it.

For images, for example, there is already a method that you can use MediaStore.Images.Media.insertImage (ContentResolver cr, String imagePath, line name, line description)

we posted this solution in a discussion today , and a few minutes later a Google engineer told us about Context.getExternalMediaDir (), which is supposed to give you a private path to the secondary external storage (aka, SD card) that MediaScanning supports.

"The new android.content.Context.getExternalMediaDirs () file returns the paths to these directories on all shared memory devices."

My guess (I have not tested) is that the directory path will be something like strings

/ storage / extSdCard / Android / media /

The one who started managing development decisions using an SD card is a real jerk, the motive for a bad decision, poor decision making, and hell, we've seen from Google Android the last two weeks starting to remind me of Microsoft.

+2
source

All Articles