I am still quite new to Android development. I'm trying to take a photo using the camera and save it to the devices storage. The app was crashing and after debugging I realised it's because the devices external storage is not mounted. How do I handle this? Can I mount the storage or is my app just unable to store data on this particular device?
Thanks
Update:
There was an answer chosen to this question but it seems to have been deleted... It linked me to these docs: http://developer.android.com/reference/android/os/Environment.html
Make sure you are using Environment.getExternalStorageDirectory() and not hard coded strings.
Some systems use /sdcard and some /mnt/sdcard or even /mnt/sdcard2.. Since you didn't post any code I cannot be sure if this solves the issue.
http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory%28%29
Related
I am developing a soundboard application in which I need to get the specified audio file from the server when the user requests it, but I don't want to stream it or download it every time, just the first time so I was thinking of caching it someway.
I made some research and I found the ExoPlayer library from google but I think it's kinda overkill for my purpose and I can't seem to get my head around it as I'm not so experienced in android development.
Is there any library that I can use?
If not, how can I make the process myself?
Save it to the file system the first time. Then you never have to download it again.
I know for sure that Firebase can work offline and store locally any changes you made to the database and whenever he get connection again upload the changes, when you're coding on android. This can be used in any Java aplication, or is it only in android? I've searched but find nothing about this. Thanks in advance!
firebaser here
Disk persistence is only available on iOS and Android. It is not available in the Java Admin SDK.
is it only in android? -- No, as you know Firebase is a technology that permits you to make mobile and web applications with no server-side programming so that development turns out to be quicker and easier.
You can use Firebase with-
Android
Unity
IOS
Web and more
Check this SO question.
Also, here is what I found.
File.canWrite() returns false on some devices although
permission provided.
In my application I need to write data to External Sd Card. However this works on some devices but fails on
some other .
for instance
Works : Limebox Internal Flash, SDCard, android OS: 2.3.3
Samsung Sdcard, extSdcard, android OS: 4.0.3
Fails : Leoxys sdcard, extsd android OS:4.0.3
How to find out Android Compatible Devices Dynamically i.e
which allow External SD card write operation. myfile.canWrite
Detail:
The getExternalSD() is an user defined function which will return the external sdcard path
In my case the external Sdcard path is "/mnt/extSdcard" (or) "/mnt/extsd"
I am finding the external sdcard path by reading the file "/system/etc/vold.fstab"
Here is some code Snippet : it creates a folder in the external sdcard.
On some devices , myfile.canWrite() returns False and I am unable create folder.
String sdcardpath = getExternalSD();
System.out.println("the sdcard path is:"+sdcardpath.trim().toString());
tv = (TextView) findViewById(R.id.textView1);
tv.append("the sd card path is:"+sdcardpath);
File myfile = new File(sdcardpath);
tv.append("\n the extsd is readable or not:"+myfile.canRead());
tv.append("\n \n the extsd is writable or not:"+myfile.canWrite());
if(myfile.canWrite()){
File testfile = new File(sdcardpath, "test");
if(testfile.exists()){
}else{
boolean mkdir = testtlie.mkdirs();
if(mkdir == true){
tv.append("\n\n the path is:"+sdcardpath.trim().toString()+"/myfile");
}else{
tv.append("\n File does not have permissions");
}
}
}else{
System.out.println("the external sd card does not have write permissions");
tv.append("\n\n the external sd card does not have write permissions");
}
xml file snippets.
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
I would like to get suggestions on
a. Are there any apis that lets the Developer know if the Devices is Truely Android compatible ?
b. Why there are difference in behaviour on different hardware devices. Is this related to firmware ?
c. Are there any alternate ways to achieve write on this kind of hardware ?
I alreday tried modifying permissions of file "platform.xml" under /system/etc/premissions/ using terminal Emulator
But I am not able to open the file in write mode
By default android provides Environment.getEnternalStorageDirectory().
But the library returns the "/mnt/sdcard" which will be the internal memory in some devices.
Your inputs will be greatly appreciated !!
File.canWrite() returns false on some devices although permission provided.
That is because there is no permission for what you are trying to do.
In my application i need to write data to External Sd Card
Android applications do not necessarily have access to "External Sd Card". Not all devices even have "External Sd Card". Hence, your "need" is flawed and needs to be replaced.
How to find out Android Compatible Devices Dynamically i.e which allow External SD card write operation. myfile.canWrite
You don't.
In my case the external Sdcard path is "/mnt/extSdcard" (or) "/mnt/extsd"
Those paths may exist on some devices for some firmware versions. Whether there is "External Sd Card" is up to the device manufacturer. Whether it is mounted, and if so, at what point, is up to the device manufacturer. What the permissions are is up to the device manufacturer. And those answers may change at any time, on any device, with a firmware upgrade.
I am finding the external sdcard path by reading the file "/system/etc/vold.fstab"
That is incrementally better than random guessing, but you are going well beyond the scope of the Android SDK.
On some devices , myfile.canWrite() returns False and I am unable to create folder.
Of course.
By default android provides Environment.getEnternalStorageDirectory().
This returns a File pointing to external storage -- what the user will have access to if they attach a USB cable between the device and a host computer and mount external storage as a drive or volume.
a. Are there any apis that lets the Developer know if the Devices is Truely Android compatible ?
What you are trying to do is not "Truely Android compatible". The devices are fine -- your expectations are not. Please fix your expectations.
Why there are difference in behaviour on different hardware devices.
Anything that is outside the scope of the Android SDK is up to device manufacturers. They can do what they want.
Are there any alternate ways to achieve write on this kind of hardware ?
Nothing that will be reliable. Just use official external storage (e.g., getExternalFilesDir()). Or, build your own ROM mod that you control, so you dictate the terms of what non-standard mount points exist and what their read/write permissions are, and use that ROM mod on whatever devices you wish to and can.
to your question b: because (unfortunately) there's still no real standardization on Android, APIs may vary by manufacturer and you can often face device-specific problems. A good example is the getData() method which returns null on Samsung 2.3.x devices.
Environment.getEnternalStorageDirectory() - I suppose this will return internal memory directory only on devices which do not have an sd-card so I don't see a problem there.
Thanks Commonsware,Maver1ck for your inputs and advise.
Android applications do not necessarily have access to "External Sd Card".Not all devices even have "External Sd Card". Hence, your "need" is flawed and needs to be replaced
The Android app in question is custom application for a specific need and is not
intended to be typical android market app. This app fetches the data from a network server
and stores it onto external Sdcard. As the data is Huge ,phone memory is too small
for the same.
Nothing that will be reliable. Just use official external storage (e.g., getExternalFilesDir()). Or, build your own ROM mod that you control, so you dictate the terms of what non-standard mount points exist and what their read/write permissions are, and use that ROM mod on whatever devices you wish to and can.
I will study on the ROM Modules and pursue this problem further.
I am writing an application that will allow an android phone and java application on the computer to communicate over the USB cable. Using Bluetooth or Wifi is not an option in this case.
I found it very difficult to find a nice solution to this problem, and the Host/Accessory libariries seemed designed to hook the phone up to docks/cameras/circuitboards rather than simply a PC. This is my solution, let me know if there are better alternatives:
I'm going to create a Java application to use ADB to push files onto the phone, the phone will then check those files for changes and act accordingly.
It seems to work well so far, except I am using the /sdcard/ folder to hold these files. I want this app to work on phones without SD cards too, so I want to know if there is some other safe folder that I can count on being able to access from the PC with ADB and the android app as well.
(I have looked at INTERNAL STORAGE libraries, but I don't know where they store their data and if I can push/pull with them from ADB.)
Thanks in advance for any help!
Read this https://groups.google.com/forum/?fromgroups#!topic/android-developers/tZrxqZQLh98
Nice discussion about holding tmp files.
Do u want to control your application from PC? Cant you use Intents launched by ADB for that?
Another options port forwarding over USB with ADB:
adb forward tcp:6100 tcp:7100
adb forward tcp:6100 local:logd
Personally I end-up doing GET requests to my local Apache server to fetch data.
Or on rooted device many folders become available.
I'm pretty new to android so apologies if I'm missing an obvious solution, I'm developing an android app that would be used to record various data including photographs and hopefully the intention would be for this collected data to be uploaded to a desktop application where certain desktop specific jobs could be carried out.
Due to the fact I intend to save photographs within the app in the SQLite database as a bytearray which recorded information would be I think that it would be too data intensive to send to a server, plus I wouldn't want the desktop app to necessarily be on a server, it should be standalone. I'd prefer to use the USB connection and allow a USB upload of the data from the app sqlite db direct to the database on the pc, probably sql server. What would be the best way to approach this? Could the android ADB be used to acheive this?
Any help or suggestions on this would be much appreciated.
Regards
I believe that your sqllite database (as well as photos contained there) will be stored on the SD card of the device. You have to options here, first, when your desktop applications find the folder on the device SD card (should be mounted on the filesystem after connecting the device to your PC), second is to use bluetooth and initialize the transfer from the device to your desktop application.
You could try having them on the same network and having them interact that way. I know applications such as RemoteDroid do this, but I have no experience doing so myself. There is also the fact that there is the data saved on the sd card / by putting your device in Storage mode and you could just point your desktop to the device drive and assume a designated folder your app uses exists.
Adding on to the answers here, you could save your photos as files in your sd card and transfer it to your pc from there.
Here is a dev guide on storing files.
Another way is to transfer over WiFi. Ice cream sandwich seems to have a WiFi Direct api that allows us to perform P2P transfers over WiFi. I have not used it yet but have a look at this
Solution 1
I would probably use rsync between my desktop and android. This way you can export data from your sqlite to a flat file and import it to your local database on your desktop. This way you can also put your schema into a file.
RSync is a very stable protocol to exchange files.
Solution 2
You can also use Amazon S3 for this purpose. The file name can contain the version number for ensuring that you have the latest file.