Android was programmed to enforce the installation of applications into the phone's memory

  • 2020-11-20 06:14:24
  • OfStack

This article describes the Android programming implementation of the application forced into the mobile phone memory method. To share for your reference, the details are as follows:

android:installLocation was introduced in Froyo(android 2.2,API Level:8). Setting this property allows developers and users to decide where to install the application.

android:installLocation belongs to the manifest node in ES14en.XML. As shown below:


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="string"
   android:sharedUserId="string"
   android:sharedUserLabel="string resource" 
   android:versionCode="integer"
   android:versionName="string"
   android:installLocation=["auto" | "internalOnly" | "preferExternal"] >
 . . .
</manifest>

android:installLocation can be set to any of the three values of "auto", "internalOnly", and "preferExternal".

auto: The program may be installed on external storage media (for example, SD Card), but by default it will be installed into the phone's memory. When the phone's memory is empty, the program will be installed on the external storage medium. Once the program is installed on the phone, the user can decide whether to place the program in external storage or in memory.

internalOnly: Default. When set to this value, the program can only be installed in memory, and if memory is empty, the program will not be installed successfully.

preferExternal: Program is installed on external storage media, but there is no guarantee that program 1 will be installed on external storage media. When the external storage medium is not available or empty, the program is installed into memory. Programs using the for ES37en-ES38en mechanism will also be installed in memory, as external storage does not support this mechanism. After the program is installed, users are free to switch whether the program should be on external or internal storage media.

Note: When a program USES the Copy Protection feature of Google Play, it can only be installed in memory.

When the program is installed on external storage media:

.apk files will be moved to external storage media, but the program data will still be in memory
The container of the.apk file will be encrypted with a randomly generated key, so that only Settings that install the program can use the data that exists on the external storage medium.

Warning: When external storage media is uninstalled, programs installed on external storage media will be terminated immediately!

Backward compatibility:

When android:installLocation is declared, but android:minSdkVersion is less than 8, we compile with AVD of not less than Froyo, so that android:installLocation will be ignored in systems less than Froyo, and Fro yo will be used in systems not less than Fro yo as specified by us.

We should not install our program on external storage media when our program has the following behavior:

1) Service
The running service will be terminated and the service will not be restarted when the external storage media is reloaded.
(2) Alarm Service
The alarm service will be canceled and the developer will have to re-register the alarm service after the external storage media is reloaded.
(3) Input Method Engines
The input method will be replaced by the system input method. When the external storage medium is reloaded, the user can start our input method through the system Settings
(4) Live Wallpapers
Our dynamic wallpaper will be replaced with the default dynamic wallpaper. When the external storage medium is overloaded, the user can replace it.
(5) Live Folders
Our dynamic folder will be removed.
6 App Widgets
Our widget will be removed, and it will usually only be available after the system is restarted.
All landowners Account Managers
Accounts created with AccountManager will disappear until the storage media is reloaded.
Today Sync Adapters
Our synchronization feature is only available when the external storage media is reloaded
Pet-name ruby Device Administrators
Our DeviceAdminReceiver will fail
The event ended when the listening device was turned on
The system will send ACTION_BOOT_COMPLETED broadcast before loading the external storage medium. Therefore, programs installed on external storage media will not be able to accept boot broadcasts.

Often, as long as we don't use the above features, we can install our programs on external storage media. For example, big game programs. When our APK file is several M large we should seriously consider whether to move the program to external storage media to help users save memory.

I hope this article has been helpful in Android programming.


Related articles: