Android External storage path, toast optimization problem

Source: Internet
Author: User

Path optimization:

When the API is not used:

// External storage space path "Sdcard/info.txt" or "Storage/sdcard/info.txt" File file =new file ("Sdcard/info.txt");

Using the API:

// use the API to return a file object whose path is the true path of the SD card File File =new file (Environment.getexternalstoragedirectory (), "info.txt");

Toast Optimization:

When not optimized:

// Create a Toast dialog box /* The first parameter on the context, and activity is originally the subclass of the context, so directly fill this */ /* The third parameter is the continuous display time, with only Length_short (2S) and Length_long (5s) Options */         Toast T= Toast.maketext (This, "login successful", Toast.length_short); // Show Toast dialog box t.show ();

After optimization:

/* *toast.length_short=0*toast.length_long  =1*/toast.maketext (This, "Login successful" , Toast.length_short). Show ();  // 0 Toast.maketext (This, "login successful", Toast.length_long). Show ();  // 1

SD Card Detection Status:

// Media_unknown: SD card not recognized // media_removed: no SD card // MEDIA_UNMOUNTED:SD card exists but not mounted // MEDIA_CHECKING:SD Card is being prepared . // MEDIA_MOUNTED:SD card is already mounted and available    

So use:

If the phone is plugged into an SD card and the application has the ability to read and write the SD card, the following statement returns True
If
(Environment.getexternalstoragestate (). Equals (environment.media_mounted)) { // Read-write file Operation }else{ Toast.maketext (this, "SD card is not available Yo-Pro", 0). Show ();

Android External storage path, toast optimization problem

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.