I have a problem writing to an SD card, here is the code: (Sorry for the code layout, just copy it)
public class SaveAndReadManager { private String result; private String saveFileName = "eventlist_savefile"; public String writeToFile( ArrayList<Event> arrlEvents ){ FileOutputStream fos = null; ObjectOutputStream out = null; try{ File root = Environment.getExternalStorageDirectory(); if( root.canWrite() ){ fos = new FileOutputStream( saveFileName ); out = new ObjectOutputStream( fos ); out.writeObject( arrlEvents ); result = "File written"; out.close(); }else{ result = "file cant write"; } }catch( IOException e ){ e.printStackTrace(); result = "file not written"; } return result; } public boolean readFromFile(){ return false; } }
I have not implemented readFromFile () yet. The problem is that root.canWrite () returns false all the time. Here is the manifest file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".InfoScreen" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
<activity android:name=".EventCalendar" android:label="@string/app_name" /> <activity android:name=".MakeEvent" android:label="@string/app_name" /> <activity android:name=".ViewEvent" android:label="@string/app_name" /> </application> <uses-sdk android:minSdkVersion="8" />
I asked for permission to write, and on my avd, if I go to settings โ SD card and phone, I will say that I have 1 gb on the SD card for recording. Please, help.
Thanks:)
lands source share