Bloggers in the learning process just found a question about the Android to SDcard Read and write,
There is no read and write permission to prompt for this configuration.
The configuration checklist in the Androidmanifest.xml file is as follows
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "Com.example.custom"
Android:versioncode= "1"
Android:versionname= "1.0" >
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-sdk
Android:minsdkversion= "8"
Android:targetsdkversion= "/>"
<application
Android:allowbackup= "true"
android:icon= "@drawable/ic_launcher"
Android:label= "@string/app_name"
Android:theme= "@style/apptheme" >
<provider
Android:name= "Custom_content_provider. Regioncontentprovider "
android:authorities= "Mobile.android.wang.hao.regioncontent"/>
<activity android:name= "Custom_content_provider. Main ">
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
The code to write the file to SDcard is as follows
Open Database
Private Sqlitedatabase OpenDatabase () {
LOG.D ("Error", "OpenDatabase");
InputStream is = null;
FileOutputStream fos = null;
try{
if (Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {
Get file directory
String dbfilename = environment.getexternalstoragedirectory () + "/region.db";
LOG.D ("error", Dbfilename);
if (! ( New File (Dbfilename). Exists ()) {File does not exist copy
is = GetContext (). Getresources (). Getassets (). Open ("region.db");
FOS = new FileOutputStream (dbfilename);
byte[] buffer = new byte[8192];
int count = 0;
while ((Count=is.read (buffer)) >0) {
Fos.write (Buffer,0,count);
}
}
}else{
LOG.D ("Error", "no Read and Write permission" +environment.getexternalstoragedirectory () + "/region.db");
}
}catch (Exception ex) {
LOG.D ("Error", Ex.getmessage ());
}finally{
Close Flow slightly ...
}
return null;
And then run the prompt without permission to access the SDcard path, but we configured also configured, the Internet is said to be the SDK version of the problem,
Said 2.2 after the version can not be used to create a FileOutputStream file, engaged in a half-day, or the same, finally I used a mobile phone test a bit,
Found the file created successfully, suddenly, I thought about it, whether there is sdcard it?
D---------, the problem actually out here, is not the virtual machine loaded sdcard, and then, I restarted a, OK fix