Android Development Series (7): stores files in SDCard, androidsdcard
Generally, the default storage space of our mobile app is in the memory of the mobile phone, but for large files such as video and audio, we can store it in SDCard:
The following code stores the file in SDCard (only core code is implemented)
First,
In the previous article, I introduced how to query the multimedia files in the sdcard in the program and display them in the playlist. However, if you delete or add some multimedia files in the sdcard, how can I update the playlist? Here I will share some of my solutions in the project, hoping to help you. First of all, I will briefly introduce how Android scans
Android-SDCard Data Access Environment Introduction, androidsdcard access
1: Introduction to Environment:
Environment is android. A class under the OS package. Google officially explained it as: Provides access to environment variables (variables that provide the access environment). It can be seen that this class is a device category class used by programs to a
) MEDIA_MOUNTED_READ_ONLY (SDcard exists and can only be read) of course there are other statuses that can be found in the document
5: getRootDirectory () obtains the Android Root path.
6: isExternalStorageEmulated () returns a Boolean value to determine whether the external settings are valid.
7: isExternalStorageRemovable () returns a Boolean value to determine
path of the sdcard for read by the Java file class. Finally, a ImageView object is created and loaded into the linear layout linearLayout1.Package Com.sdcardread;import Java.io.file;import Android.os.bundle;import android.os.environment;import Android.widget.imageview;import Android.widget.linearlayout;import Android.widget.textview;import Android.app.activity;import Android.graphics.bitmap;import Android.
(). GetAbsolutePath (); Gets the absolute path of the sdcard for read by the Java file class.Finally, a ImageView object is created and loaded into the linear layout linearLayout1.Package Com.sdcardread;import Java.io.file;import Android.os.bundle;import android.os.environment;import Android.widget.imageview;import Android.widget.linearlayout;import Android.widget.textview;import Android.app.activity;impor
MYAVD2This allows the emulator to see its own sdcard, which can be viewed via the ADB shell.2: Traverse SDcardHow to find some special path in Android, such as SDcard this special path, actually just look atAndroid.os.Environment This class is very clear, which has the foll
can read and write) media_mounted_read_only (SDcard exists, can only read) Of course, there are other states that can be found in the document
5:getrootdirectory () get to the Android root path
6:isexternalstorageemulated () returns a Boolean value to determine whether the external setting is valid
7:isexternalstorageremovable () returns a Boolean value that
The examples in this article describe the way in which the Android programming read assets All files (traversing each folder) into the SDcard. Share to everyone for your reference, specific as follows:
private void Copyassets (String assetdir, string dir) {string[] files;
try {//Get assets altogether how many files = This.getresources (). Getassets (). List (Assetdir);
catch (IOException E1) {
Android sdcard storage solution (based on wrapfs File System)
The previous two articles mainly describe the fuse-based sdcard storage solution for android. For details, refer:
Android sdcard storage solution (based on fuse file s
The example in this article describes how Android programming obtains SDcard card information. Share to everyone for your reference, specific as follows:
public static Sdcardinfo Getsdcardinfo () {String sdcstring = Android.os.Environment.getExternalStorageState (); if (Sdcstring.equals (Android.os.Environment.MEDIA_MOUNTED)) {File Pathfile =
Android.os.Environment.getExternalStorageDirectory ();
The right to join the access SDcard in Androidmanifest.xml is as follows:
The code is as follows
Copy Code
The code is as follows
Copy Code
Then we use SDcard to read and write, we use a few static methods below the Environment class
1:getdatadirectory () gets to the data directory in Androi
2:getdownloadcachedirectory ()
I. Basic outline1. Description:1> the data files used to run the application can be saved to the SD card2> file Type: arbitrary3> Data Save path:Path 1:/storage/sdcard/android/data/packagename/files Other apps can access, remove when applying uninstallPath 2:/storage/sdcard/xxx/(indicates that the file you created--xxx) can be accessed by other apps and will not
and is used to display it on the playback interface.Path of the music file (used when deleting the file ).Next, define a variable to locate the selected music:private int pos;Next, store the information of the music file in the corresponding array:c.moveToFirst();_ids = new int[c.getCount()];_titles = new String[c.getCount()];_path = new String[c.getCount()];for(int i=0;iSomeone may ask why the format of the obtained path is _
preparation of Mainactivity.java. Here we first insert two tool classes, one in "Java" read all directories and files under the path (click the open link) said. Used to traverse the file above the SDcard, of course, when traversing the SDcard on Android this system directory. Do not remove the words will be the system
The project uses a large dB file, which is developed by the simulator in the early stage. Therefore, we want to push the db to the sdcard and then read it:
The procedure is as follows:
1, run-> cmd-> E:-> Cd E: \ Pd \ android-sdk_r18-windows \ tools
2. emulator mksdcard 1024 M sdcard. img
3. Start the simulator (loading
Create a folder on sdcard in Android, androidsdcard
// Create a folder on the SD cardPublic void createSDCardDir (){If (Environment. MEDIA_MOUNTED.equals (Environment. getExternalStorageState ())){// Create a folder object and assign it to the directory of the External StorageFile sdcardDir = Environment. getExternalStorageDirectory ();// Get a path with the fold
Hello everyone, we are going to use Android mediaplayer today
Step 1: Preparation work.
Mksdcard 512 M sdcard. img
Create a new AVD named androidsdcard
Push songs into sdcard (before you push, you make sure your AVD is running, else the operation of push will not work ):
ADB push F:/music/1.mp3/sdcard
Step 2: L
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.