[Android] Android mobile app data to SD, android mobile app

Source: Internet
Author: User
Tags home screen

[Android] Android mobile app data to SD, android mobile app

[Android] Android mobile app data to SD

 

 

You can specify it in the menifest file of the application. The <manifest> element contains the android: installLocation attribute and sets the value to "internalOnly", as shown below:

<Manifest xmlns: android = "http://schemas.android.com/apk/res/android" android: installLocation = "internalOnly"...>

Android: installLocation has two other property values: "preferExternal" and "auto". You can also understand what it means based on the literal meaning, or the description is as follows:

If you define "preferExternal", it means that you require your application to be installed in extended storage, but the system cannot guarantee that the application will be installed in extended storage. If the extended storage has no space, the system will install the application to the internal storage. You can move your application between two locations.
If you define "auto", your application may be installed in the extended storage, but there is no special preference for the installation location. The system determines where your application is installed based on many factors. You can also move an application between two locations.

 

When we use Android phones, we find that some programs are allowed to be moved to the SD card, but some cannot? Why?

Because Android 2.2 and later versions are allowed to be moved to the SD card. However, all applications developed earlier do not have this function.

So how can I allow your app to move to the SD card? The answer is actually very simple. You only need to set an installLocation attribute for Manifest.

This property sets the default installation location. There are three valid values: auto, internalOnly, and preferExternal.

Auto indicates automatic. The installation location is determined by the system.

InternalOnly is installed in mobile phone memory

PreferExternal is installed in External Storage

 


 

Take a look at the modified AndroidManifest. xml.

 

<manifest xmlns:android="http://schemas.android.com/apk/res/android"        package="com.yfz"        android:installLocation="auto"        android:versionCode="1"        android:versionName="1.0">


Is it easy?

 

Someone may ask, what if I want to support 2.1? In fact, you don't need to worry about it. You just need to set <uses-sdk android: minSdkVersion = "7"/> and then install it on the 2.1 device, Android ignores this attribute, install it directly to the phone memory.

 

Note that not all programs are suitable for moving to the SD card. Next let's take a look at the conditions under which programs are not recommended to be moved to the SD card.

Applications That shoshould NOT Install on External Storage

When the user enables USB mass storage to share files with their computer (or otherwise unmounts or removes the external storage), any application installed on the external storage and currently running is killed. the system provided tively becomes unaware of the application until mass storage is disabled and the external storage is remounted on the device. besides killing the application and making it unavailable to the user, this can break some types of applications in a more serious way. in order for your application to consistently behave as expected, you shocould not allow your application to be installed on the external storage if it uses any of the following features, due to the cited consequences when the external storage is unmounted:

Services
Your running Service will be killed and will not be restarted when external storage is remounted. you can, however, register for the ACTION_EXTERNAL_APPLICATIONS_AVAILABLE broadcast Intent, which will modify y your application when applications installed on external storage have become available to the system again. at which time, you can restart your Service.
Alarm Services
Your alarms registered with AlarmManager will be canceled. You must manually re-register any alarms when external storage is remounted.
Input Method Engines
Your IME will be replaced by the default IME. When external storage is remounted, the user can open system settings to enable your IME again.
Live Wallpapers
Your running Live Wallpaper will be replaced by the default Live Wallpaper. When external storage is remounted, the user can select your Live Wallpaper again.
Live Folders
Your Live Folder will be removed from the home screen. When external storage is remounted, the user can add your Live Folder to the home screen again.
App Widgets
Your App Widget will be removed from the home screen. when external storage is remounted, your App Widget will not be available for the user to select until the system resets the home application (usually not until a system reboot ).
Account Managers
Your accounts created with AccountManager will disappear until external storage is remounted.
Sync Adapters
Your AbstractThreadedSyncAdapter and all its sync functionality will not work until external storage is remounted.
Device Administrators
Your DeviceAdminReceiver and all its admin capabilities will be disabled, which can have unforeseeable consequences for the device functionality, which may persist after external storage is remounted.
Broadcast Receivers listening for "boot completed"
The system delivers the ACTION_BOOT_COMPLETED broadcast before the external storage is mounted to the device. If your application is installed on the external storage, it can never receive this broadcast.
Copy Protection
Your application cannot be installed to a device's SD card if it uses Android Market's Copy Protection feature. however, if you use Android Market's Application Licensing instead, your application can be installed to internal or external storage, including SD cards.
If your application uses any of the features listed above, you shoshould not allow your application to install on external storage. by default, the system will not allow your application to install on the external storage, so you don't need to worry about your existing applications. however, if you're certain that your application shocould never be installed on the external storage, then you shoshould make this clear by declaring android: installLocation with a value of "internalOnly ". though this does not change the default behavior, it explicitly states that your application shocould only be installed on the internal storage and serves as a reminder to you and other developers that this demo-has been made

 

It is important to see the above section. For example, if your program wants to start automatically, it cannot be moved to the SD card. Because the boot broadcast message BOOT_COMPLETE is sent before the SD card is loaded, the program cannot receive it.


How to move the Android app to the SD card

If you are scared by the warning "insufficient mobile phone memory space", then the Android 2.2 System is definitely your gospel. you can install applications to the mobile phone memory, then, transfer the application data to the SD card. The operation is to go to the mobile phone Settings> Application> Manage the application, and click the relevant application. If the application supports this function, click "move to SD card" to move the program data to the SD card, but note that the system core file will still be stored in the phone memory. In addition, you can install the SDMove program to help the transfer program, because the transfer program provided by the Android 2.2 System to the SD card function is very cumbersome, this is especially troublesome when your mobile phone runs many applications. by installing the SDMove application, you can see at a glance which programs support moving to the SD card and which are not supported, the operation is much more convenient than the system itself, saving a lot of time.

How does android move the content of the sqlite database to the SD card?

1. Open the DDMS view in Eclipse
2. Select the device currently connected to the mobile phone.
3. Open the SD card File directory in File Explorer
4. Import the sqlite database file to the directory you need to store.
 

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.