About the Android sdcard storage problem _android

Source: Internet
Author: User
Tags file permissions

Use the Activit openfileoutput () method to save the file, the file is placed on the phone on the inside;
Note: The emulator creates a SDcard card image file that can be created in the creation simulator, or in a DOS window for the Android SDK installation path Tools directory, and enter the following command: Mksdcard 2048M D:\AndroidTool\ Sdcard.img
Access to SDcard in your program requires the following permissions :
Create and delete file permissions in SDcard
<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
Write Data permissions in SDcard
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>

public void Savetosdcard (string filename, String filecontent) throws IOException {
File File = new file (environment.getexternalstoragedirectory (), filename);//Get SDcard Path
FileOutputStream OutStream = new FileOutputStream (file);
Outstream.write (Filecontent.getbytes ());
Outstream.close ();
}

// to determine if the SD card exists and can read and write
//if (environment. Getexternalstoragestate (). Equals ( environment.media_mounted)) {
//Fs.savetosdcard (FILENAMESTR, FILECONTENTSTR);
//Toast.maketext (Getapplicationcontext (), r.string.success, 1). Show ();
//} else {
//Toast.maketext (Getapplicationcontext (), R.string.sdcarderror, 1). Show ();
// }

Related Article

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.