I am trying out a test application on an Android emulator. I would like the app to write data to a file that is stored on my C drive. I have read and written data off Samba drives and webservices, but reading and writing to my local hard seems to be a puzzle. I tried filePath = "file:///C:/test/input/"; to point it as my parent folder, but the Emulator doesn't seem to recognize the directory, and I get a 'not found' error.
Any ideas will be appreciated. Thanks.
I would like the app to write data to a file that is stored on my C drive.
That is not possible, unless that file is accessible via some server. The Android SDK emulator does not have access to the filesystem of the developer PC.
Given that you are using an android emulator I am guessing it is setting up some special folder to act as a proxy for the androids hard drive. Meaning that the android emulator doesn't understand what your C drive is and instead is looking in it's 'hard drive' for a file. Find out where the emulator puts files for android, it could be a temp folder, and store your file there.
Edit: Where is Android Emulator Internal Storage this question should help you find where the files should be stored and the naming conventions.
If you don't care using genymotion emulator instead you can refer to this answer, pointing to this post, it has just what you need
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
For my app I want to send the user a text file of data on an e-mail which they save in the download folder on their Android device.
The app will then pull the data from that file and use it in the app. In the desktop version URLLoader works fine with the file copied into the app source directory, but that method does not work on an Android device.
Storage permission is set.
I have tried using the Filestream method and manually copying the file into the app directory on the device, but that does not seem to work.
Ideally I want to be able to set path for the file to the device's download folder so that the user experience is as simple as it can be.
And before you ask, usage will be on wifi only tablets with questionable wifi access - sending e-mails with the file upfront is the only reliable way to handle this.
Thanks for any suggestions.
Adam
In mobile devices the File.applicationDirectory , is a read only folder, try to use File.applicationStorageDirectory
https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html#applicationDirectory
https://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7fe4.html
I have an Android application that generates some data (simple text file) that I would like to transfer to my PC for further processing. My understanding is that my storage options for a place to save such a file are a) internal storage or b) external storage. My device is a rooted Nexus 7 running Marshmallow, and I can't get either option to work.
With internal storage I'm able to write the file but then it's nowhere to be found using ADB or Eclipse DDMS. With external storage I'm getting FileNotFoundExceptions which I'm guessing are due to new complicated permissions, so none of Android saving file to external storage is working.
Is this possible and, if so, is there an easy way to do it?
What is your targetSdkVersion? If you target 22 and below, the new permission policy won't take effect.
It is possible to write a text file in Android and read the same in your PC using external-storage.
This app does the same.
You can find a simple example here.
If this does not work for you, kindly share your code-snippet that writes the file.
I have developed an Android app using Appcelerator Titanium. This app will create a file in applicationDataDirectory and install a database as well.
If run on emulator, I can locate those files using "adb" command. But how about on Android device? Can I use the "My Files" app to view those file I created? (since I can see files created by other application there.)
Moreover, I expect once I removed the app on device, it will automatically remove the related files and database. Is that true?
Because I found that even I removed the app from the device, the database seems left behind. I can tell because after deleting app and re-run on device(from Titanium), it show previous data.
I am using Ti SDK 2.0.1GA2, Android Runtime V8. And using Samsung Galaxy Tab for testing.
Thanks in advance.
Application Private Data files are stored within <internal_storage>/data/data/<package>
Files being stored in the internal storage can be accessed with openFileOutput() and openFileInput()
When those files are created as MODE_PRIVATE it is not possible to see/access them within another application such as a FileManager.
On Android 4.4 KitKat, I found mine in:
/sdcard/Android/data/<app.package.name>
Use Context.getDatabasePath(databasename). The context can be obtained from your application.
If you get previous data back it can be either a) the data was stored in an unconventional location and therefore not deleted with uninstall or b) Titanium backed up the data with the app (it can do that).
You can get if from your document_cache folder, subfolder (mine is 1946507). Once there, rename the "content" by adding .pdf to the end of the file, save, and open with any pdf reader.
This is a simple way to identify the application related storage paths of a particular app.
Steps:
Have the android device connected to your mac or android emulator open
Open the terminal
adb shell
find .
The "find ." command will list all the files with their paths in the terminal.
./apex/com.android.media.swcodec
./apex/com.android.media.swcodec/etc
./apex/com.android.media.swcodec/etc/init.rc
./apex/com.android.media.swcodec/etc/seccomp_policy
./apex/com.android.media.swcodec/etc/seccomp_policy/mediaswcodec.policy
./apex/com.android.media.swcodec/etc/ld.config.txt
./apex/com.android.media.swcodec/etc/media_codecs.xml
./apex/com.android.media.swcodec/apex_manifest.json
./apex/com.android.media.swcodec/lib
./apex/com.android.media.swcodec/lib/android.hidl.memory.token#1.0.so
./apex/com.android.media.swcodec/lib/libcodec2_soft_common.so
./apex/com.android.media.swcodec/lib/android.hardware.graphics.mapper#2.0.so
./apex/com.android.media.swcodec/lib/libcodec2_soft_vorbisdec.so
./apex/com.android.media.swcodec/lib/libcodec2_soft_h263dec.so
./apex/com.android.media.swcodec/lib/libhidltransport.so
./apex/com.android.media.swcodec/lib/libcodec2_soft_h263enc.so
./apex/com.android.media.swcodec/lib/libcodec2_vndk.so
./apex/com.android.media.swcodec/lib/android.hardware.graphics.mapper#2.1.so
./apex/com.android.media.swcodec/lib/libmedia_codecserviceregistrant.so
./apex/com.android.media.swcodec/lib/libhidlbase.so
./apex/com.android.media.swcodec/lib/libcodec2_soft_aacdec.so
./apex/com.android.media.swcodec/lib/libcodec2_soft_vp9dec.so
.....
After this, just search for your app with the bundle identifier and you can use adb pull command to download the files to your local directory.
I am working with SQLite in an App. It writes to the database, etc., with no problem. However, I can not find this new database. I have tried changing the directory with cd /data/data/packageName/databases, but it says "no such file or directory". Also, this database is not found when I click on the File Explorer in eclipse. My logging tells me the database was created and that it is being written to. I think I need to set the path in the shell or something to that effect using adb, but I have no idea how to do that. Can anyone give me some instruction? Also, I am using my phone for development. The database also does not show up when using the emulator.
Thanks very much.
Matt
Matt,
This thread gives a good explanation on why you might not be able to access the data folder on your phone.
Can't access data folder in the File Explorer of DDMS using a Nexus One!
You can still test the Sqlite code though. Just boot up an emulator. The emulator will have no access restrictions. Once it's booted up you can use the ddms tool (located in the tools directory under your android SDK install folder). It has a File Explorer and you can download the files from the /data folder.
Also, I am using my phone for development.
You cannot access the database on a standard Android device except via your own application code.
Your options are:
Do this sort of testing on an emulator, in which case you can access the directory that you are failing to access on the device
Add a database backup feature to your app, that copies the (closed) database to external storage, so you can examine it
Root your phone (leastways, I am under the impression this can help get you to this directory -- haven't done it myself)
The database also does not show up when using the emulator.
Try harder. If you can store data in the database and read data out of it using SQLiteDatabase, then the database file is there.