Android lets apps automatically install to phone memory and determine if the app is installed in SDcard

Source: Internet
Author: User

Last time I wrote a widget program, ready to add it to the mobile home page, found that the widgets I just installed the widget, the online search data only found that the system widgets can only load scan installed in memory applications, Display the widget's app to the widget list.

For developers, how can the application be automatically installed into the phone memory?

In the Android2.2 version and later, there is a property in Andoridmanifest.xml: Android:installlocation, which can be set by setting this property of three values "Auto" | "Internalonly" | "Preferexternal" to decide where to install the application.

Auto

The program may be installed on external storage media (for example, SDcard), but it will be installed to the phone memory by default, and when the phone memory is empty, the program will be installed on the external storage media. When the program is installed on the phone, users can move themselves on external storage media and phone memory.

Internalonly (default value):

When this value is set, the program can only be installed in memory, and when the phone memory is empty, the installation is unsuccessful.

Preferexternal:

The program is installed on the external storage media, but the system does not guarantee that the program will be installed on the external storage media, and when the external storage media is not available or empty, the program will be installed in memory. If the program uses the forward-locking mechanism, it will also be installed in memory because external storage does not support this mechanism. Once the program is installed, the user can also move freely between the external storage media and the memory.


When we want to know if an application is installed in SDcard, the following statements can be used to determine:

[Java]View PlainCopy
    1. /**
    2. * Determine if the application of the package name is installed on the SD card
    3. * @return, True if install on SD card
    4. */
    5. Public Static boolean isinstallonsdcard (String packagename) {
    6. Packagemanager pm = Launcherapplication.getapp (). Getpackagemanager ();
    7. ApplicationInfo AppInfo;
    8. try {
    9. AppInfo = Pm.getapplicationinfo (PackageName, 0);
    10. if ((Appinfo.flags & applicationinfo.flag_external_storage)! = 0) {
    11. return true;
    12. }
    13. } catch (Namenotfoundexception e) {
    14. E.printstacktrace ();
    15. }
    16. return false;
    17. }

Android lets apps automatically install to phone memory and determine if the app is installed in SDcard

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.