Our game is bigger than 50Mb so we will be using an expansion file. This supposedly goes in the /Android/obb/package-name/ folder. To test it, we copy the file to that location using Windows file explorer.
To find the location, we call
String dir1 = Environment.getExternalStorageDirectory().getAbsolutePath();
However, on some device, it cant find the file
e.g. the GalaxyTab2.7.0 - the above call returns the location /storage/sdcard0, but it cant open the file /storage/sdcard0/Android/obb/package-name/base.tcf, even though we have copied it there, using Windows file explorer, to the Android/obb/package-name/ folder.
Now, maybe this "Android" folder is not the same one as the storage/sdcard one - maybe I CAN only put it on an sdcard ? But this same thing works on Nexus 10 and Sony Experia device, with the same paths, which don't have sd cards in them.
To get this working on other devices we had to put READ_EXTERNAL_STORAGE permissions in the manifest file. Maybe there is another permission ? Maybe once we actually download the expansion file, it will just work, but we can't test it otherwise.
Any ideas?
Thanks
Shaun Southern
Related
I've tried several folders but looks like no file is created.
External read & write permission have been enabled.
The code run without any sign of error. (as given below)
Here is the screenshot of the code inside mainactivity.cs (this is for testing purposes).
I also assume that since this is platform specific, the code must be in android project.
string filename = Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory, "count1.txt") ;
StreamWriter sw = File.CreateText(filename);
sw.WriteLine("asad ini test");
sw.Close();enter code here
1b. I 'm using Android 6.0 phone, but I can't find such folder /data/user...
(I'm not sure if such folder is targeted special version of Android)
I search both internal /Android/myproject/files/ and found nothing
I search external SDcard /Android/myproject/files/ and still found nothing
(please look at the my android phone folders, i can't even find /data folder
Once, this is accomplished the next step would be how to call this function from the generalproject (non android, non IOS, non UWP project).
Example to write file given in xamarin document.
Where should this code reside? in general project folder ? or, android project folder?
The term "external" used in android is very misleading. It doesn't mean the external removable SD card rather some folders that don't require "root" permission. Therefore, initially I can't find the folder which I save a file into.
Another reason is each phone manufacture uses different name, hence it is very difficult to get an absolute address of an external removable SD Card.
More details is explained in blog_external_removable_SD_Card
You can't write to the removable SD Card
an old post here
I have an html file that I placed on my Android device via USB (Android File Transfer). Android file transfer doesn't show any paths, so I don't know what directory this file is being placed in. I downloaded a file manager app on the device by ZenUI that suggests the file is in "root/sdcard/theFile.html" but referencing it in an app using "file:///root/sdcard/theFile.html" does not work even if all the appropriate Manifest permissions are in place ("file not found").
I am using a Droid Turbo 2
This is probably device-dependent. On my Nexus 6 is it
file:///storage/emulated/0/Download/file.html
(if you placed your file in Downloads).
If you have an SD-Card inside, maybe just trying emulated/1/... helps, or just download TotalCommander, navigate to the file and look up the properties of the file (Location:) will help you.
Hope that helps.
I tried writing to the sdcard folder using the emulator, with no success, although few weeks ago it worked. I get the sdcard folder, in my app, using Environment.getExternalStorageDirectory(). So I opened Android Device Monitor and I see no sdcard folder. I see a file with the name sdcard in my root folder and one in the mnt/ folder.
What is wrong?
The problem I am facing is not only that I do not see the sdcard but rather that I can not create a folder in it. I thought that if I solve the problem of not seeing it it will solve my main issue. Here is my code where isPresesnt returns false.
I also made sure that I have permission to write to the external storage.
It seems that the problem exists only with the emulator - I just tested it on my phone and it worked fine.
I also noticed that if I connect my phone to my computer while the emulator is opened, I do see the sdcard folder in the Android Device Monitor, but I do not know to which device it belongs to.
my code
File path = new File(Environment.getExternalStorageDirectory() + "/Documents");
boolean isPresent = true;
if (!path.exists()) {
isPresent = path.mkdir();
}
MANIFEST
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
permission code
perms.put(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED);
Actually we cannot see SD card folder on our emulator, but it still exist in mnt/sdcard like what you mention above. If you want to see it, just import an image to that folder and it with appear in Gallery with folder name sdcard.
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.
EDIT: After realizing I have to make things public so to speak this is what I attempted to create a folder I could see when plugging the tablet in from my pc and copying stuff over there:
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) ;
File theFile = new File(path+"/Portfolio/");
//if(!theFile.exists())
theFile.mkdir();
I commented out the if theFile.exists() cause it was always returning true.
So now I have this folder that seems to work, no errors are thrown and the folder should be created in fact I am using
Adao File Manager on the device to browse to this location it is indeed there under /Pictures/Portfolio
but when I plug it into my windows machine, i see /Pictures but no folders underneath it, am i just losing it?
Okay so
I have these little DIR is make on my tablet from my application, to put client files into. I thought I could just connect the tablet up and copy files from my PC to these folder I
had made. The thing is when I plug my acer iconia in, while it shows up and I can browse some files it seems the folder I made in the app using File.mkdir(); is this path:
/sdcard/Android/data/my.softwares.package.name/files/Pictures/somefolders
while I can use a 3rd party file browser app to see this folder does exsist as far as I can tell from windows i can only browse as far as:
/sdcard/Android/data (if im even getting there not sure).... is this really the case or am I missing something? The code I use to create these folders is:
String p = Environment.DIRECTORY_PICTURES + "/" + s.getClient().getFirstName()+s.getClient().getLastName() + "/" + s.getPackage().getName() + (mSession.getSessionDate().getMonth()+1) + mSession.getSessionDate().getDate() + (mSession.getSessionDate().getYear()+1900);
File path = mContext.getExternalFilesDir(p);
if(!path.exists())
path.mkdir();
Seems no luck here when I plug my tablet into the pc, again only can go as far as Android/data
So this is for a portfolio like program, I want to create a folder on the device, users can copy pictures to from their pc, then the same app that created the folder can read this folder later on after the pictures have all been copied over, so what am I missing since my assumption of windows being able to read everything on the sdcard seems false?
You have created the pictures in the private data area of your app and therefore do not have access to it. That would be a security problem.
Save the data to a public location like the sdcard. Just read up on external storage.
http://developer.android.com/guide/topics/data/data-storage.html#filesExternal