Android SDcard One of the read and write permissions issues

Source: Internet
Author: User

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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.