Populate listview with mp3 files found locally [duplicate] - android

I want to download some files and save them into the internal storage of the phone/tab. Tried on Samsung Galaxy Note 2 and Galaxt Tab 10.1. When I use /storage/sdcard0/ on them the code runs successfully but when I use Galaxy Nexus 3 the code fails.
I want to get absolute path of the phoe or tab's internal storage' Absolute Path.
Does it possible, if so how?

When I use /storage/sdcard0/ on them the code runs successfully but when I use Galaxy Nexus 3 the code fails.
/storage/sdcard0/ is not internal storage. It is external storage.
(BTW, since there is no device named "Galaxy Nexus 3", I am assuming that you simply meant "Galaxy Nexus")
To find locations on internal storage for your app, use getFilesDir(), called on any Context (such as your Activity, to get a File object.
To get a location on external storage unique for your app, use getExternalFilesDir(), called on any Context (such as your Activity, to get a File object.
To get a standard location on external storage for common types of files (e.g., movies), use getExternalStoragePublicDirectory() on Environment.
To get the root of external storage, use getExternalStorageDirectory() on Environment. This, however, is considered sloppy programming nowadays, as it encourages developers to just put files in random locations.

why can't you use Environment.getExternalStorageDirectory() for getting /storage/sdcard0/ path from code ?
need to add permissions as well
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

The solution found is
1st edit the emulator:
Go to Android Virtual Device Manager and then edit the emulator
Set say 100 MB for SD d card for the respected emulator, say Ok
Save and close emulator and start
It worked for me, the app is no longer giving an error and is working fine.

Related

Android | obtain the sdcard (removable) path

I've tried a lot of method and I've read a lot of posts, without find a valid soluction.
Summing:
I try to use this https://github.com/18446744073709551615/android-file-chooser-dialog to choose a directory and use it. This code work perfectly with internal storage.
With this code: System.getenv("SECONDARY_STORAGE"), on my Asus TF201 with JellyBean and with Lollipop, I have /storage/sdcard1 and I can use this with previus code and it works.
Now, the problem.
I've tried with this (and other similar solution): How can I get external SD card path for Android 4.0+? but on LG G3 with Android 6.0 I've /mnt/media_rw/9014-4EF8 and doesn't work with previous code.
How can I obtain the external sd path? I need only to read in sd. Or can I use /mnt/media_rw/9014-4EF8?

Android device internal storage full path

I am making AR video playback app.
I want to play video from device storage instead of include it in the app.
In the path field in video texture I should write the path of the internal storage.
I wrote "/storage"emulated/0/Demo.mp4" (video's name is Demo)
It works on the testing device, but when I try running the app on other device it does not work because the path differs (internal path is :/storage/sdcard0)
What is the path should I wrote in the video texture to ensure running the app whatever the device is?
To find locations on internal storage for your app, use getFilesDir(), called on any Context (such as your Activity, to get a File object.
To get a location on external storage unique for your app, use getExternalFilesDir(), called on any Context (such as your Activity, to get a File object.
To get a standard location on external storage for common types of files (e.g., movies), use getExternalStoragePublicDirectory() on Environment.
To get the root of external storage, use getExternalStorageDirectory() on Environment. This, however, is considered sloppy programming nowadays, as it encourages developers to just put files in random locations.
Hardcoding things is not the best way but you could check if the video exists in
/sdcard
/mnt/sdcard
/storage/sdcard0
/storage/emulated/0
/storage/emulated/legacyode
at least those are the most common places for android devices.
Then set the patch programatically instead of using the inspector

How does Android File Storage Work?

I am working on a project that needs to store some .txt to android, and get it from the computer for other use. From what I read from the documentation, I know that there are two types of storage: 1 Internal, which is somewhere deep in the phone that is private to the app. 2 External, which includes the SD card and the Internal Storage of the phone. I want to store it to External->Internal, and I am using this line of code to do that:
public String WalkDir = android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/Walks/";
When I logged WalkDir, LogCat says "/storage/emulated/0", I stopped the app, checked with the adb shell, and there is no folder "0" but "legacy". I unplugged the phone and plugged it back in, the "Walks" folder is now in the root directory, and I don't need adb shell to access it.
So my question is, can you help explain how this system works? Why did "0" disappear? What is "legacy"? Why is the file in Internal Storage when I unplug&plug it?
Thank you very much!
Those are what in Linux are called symlinks (like shortcuts in Windows) that various system apps in Android are using..
/storage, /sdcard are sym linked folders,that means when you open one of those, it redirects to the original(/data/media/0), as for the 0 is just a multi user feature implemented in android 4.2, but only enabled on tablet androids.
Why do this Sym-Link?: simple so it dosent break apps(not only file explorer type of app, but all apps).
Still dont get, why it would break?.Simple. android api have lots of ways to write/read files from folders, u can do manually,u can get the data path, u can get the sdcard path, etc,etc. so to not break that they just does these sym links, thats why in one app the storage contentents are listed on /sdcard but on others, is /storage, etc,etc. one example of an app that broke because of these changes to android is titanium backup, u need to change the internal storage on it, so it work.
2 mount points pointing to the same storage device and partition.
If you create something in one folder, it will show up in the other. Same applies for deleting stuff.
They do not take away more storage space, as it is only available once but shown twice.
You also don't need to worry about it in any way because file browsers normally set their default directory to one of these locations.
As far as i know, Google changed the mount points in Android 4.2 to /storage/emulated/0/ due to them switching to MTP and EXT4(?) for the sdcard. The other mount points are still there for compatibility.

Where is my sdcard location on 4.4.2?

On Android 4.4.2 Environment.getExternalStorageDirectory().getPath() returns /storage/emulated/0 but this path does not exist on my Nexus5 Android 4.4.2. Environment.getExternalStorageDirectory().getPath() worked up until Android 4.4.2.
How can I get the /sdcard path on Android 4.4.2?
This path does not exist on my Nexus5 Android 4.4.2.
Yes, it does, for your process at runtime.
For example, this sample project downloads a file to Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS). If you log the location at runtime, when running it on a Nexus 5, it is reported as /storage/emulated/0/Download. And the download succeeds.
If you are looking for /storage/emulated/0 via DDMS or adb shell, you will not find it. For those tools, default external storage is /mnt/shell/emulated/0. Hence, the downloaded file from the above sample appears in the /mnt/shell/emulated/0/Download directory.
AFAIK, the difference is tied to providing separate external storage to secondary accounts.
The Storage Options documentation says to use Environment.getExternalStorageDirectory() (as you are already correctly using). This function is available on all versions of Android.
Are you seeing it return a path that isn't actually available on a 4.2 device?
Please note (from Environment.getExternalStorageDirectory()):
Applications should not directly use this top-level directory, in order to avoid polluting the user's root namespace. Any files that are private to the application should be placed in a directory returned by Context.getExternalFilesDir, which the system will take care of deleting if the application is uninstalled. Other shared files should be placed in one of the directories returned by getExternalStoragePublicDirectory(String).
Writing to this path requires the WRITE_EXTERNAL_STORAGE permission, and starting in read access requires the READ_EXTERNAL_STORAGE permission, which is automatically granted if you hold the write permission.
Starting in KITKAT, if your application only needs to store internal data, consider using getExternalFilesDir(String) or getExternalCacheDir(), which require no permissions to read or write.
Sometimes /storage/emulated/0 can be written to, but reads fail... so tests for "writability" are not sufficient. This is such an annoying problem, I have come up with an equally annoying but effective solution.
Hardcode "/mnt/sdcard" Yea, I said it.
Looks like someone else said it first ... storing android application data on SD Card
More joy... http://forums.bignerdranch.com/viewtopic.php?f=414&t=7407

Where is android application installed in my sd card

I just want to view the files(especially the .png files) associated with one of the application in my mobile. The application is actually installed(moved) in the SD card.
The issue is ..I could not find the application in the SD card. I am using a file browser called 'File Manager' to browse through the SD card. Can someone help me on this.
It should be here:
/mnt/sdcard/Android/data/your_package_name/
Some hardware implements the path to the external storage different.
/mnt/sdcard/Android/data/your_package_name/
/mnt/sdcard-ext/Android/data/your_package_name/
You may be able to get a better view of what is on the device by using the ADB Shell. If you still have trouble at this point trying running grep or find from the shell.
UPDATE
Most of the time the files associates with your application are in the directory with your application. The application is installed in /data/data/your.package.name/. However you will need root access to get here if you are on a phone, I think the emulator lets you get here. As far as external storage... yea its a pain, to much fragmentation in the market. You have to programmatically check the location of the external storage.
On my device with Android 2.3.6 apps moved on the SD card are located into a directory named .android_secure as .asec files (see http://www.fileinfo.com/extension/asec).
They are not visible from the standard "Archive" browser which shows the hidden directory as empty.
The files are also encrypted so I guess no access to the images within is possible.

Categories

Resources