开发者

How to enable app being moved to sdcard (and support android < 2.2 still)?

How can i enable my app to be moved to the sdcard?

-edited the title in order to make questio开发者_如何转开发n more relevant to the answers given.


You have to set android:installLocation entry in AndroidManifest.xml file (preferExternal or auto values will do).

NB! For this build target should be API Level 8 (Android 2.2).


You can also set the android:installLocation and still target to Android 1.6.

In your AndroidManifest.xml you have to insert the min SDK Version like that

    <uses-sdk android:minSdkVersion="4" />

This will make sure your application works only on Android 1.6 and higher. This will of course, cause an compiler error in your Eclipse project sapce. That's because the 1.6 SDK don't know about the android:installLocation. To fix this, right-click on your Project in the Eclipse Project space (assuming you're using Eclipse, don't know how it works in other IDEs or with Ant build) then go to the "Android" Option and select "Project Build Target" to Android 2.2.

This will remove the error shown above and you can compiler/export your APK file. This way the APK will work on Android 1.6-2.1 as usual and on Android 2.2 it will enable you to use SD card to install/move the app too.

However a Word of Warning: This can be a source of incompatibility, if you're not careful. So an increased testing phase is required, because you won't notice directly if you use an 2.x feature, because Eclipse wont show it as error, because it uses the Android 2.2 SDK as reference.

So you basically have 2 choices: 1. Only do the steps above when you're exporting/signing your app (i.e. just before you're about to publish this new version) and then set it back or 2. Extensively test your Applications on 1.6 Device or Emulator and see if it crashes at any point, because the App uses a feature only available on newer OS' than 1.6.

Depending on the compexity of your application, the first one is usually the safer one, however bears the risk that you forgot to do it once. This would have the consequence that for this one update the user won't have the possibility to install it on SD card. Choice 2 has the problem, that if you don't test everything well enough, you App may suddenly ForceClose when an Android 1.6 devices try to call features/functions only available in 2.x.


Please follow the below procedure for Android phones.

  1. Copy the Android SDK to your system.
  2. Connect your mobile to system and enable USB debugging option in your mobile.
  3. Open cmd line and go to the path android sdk\platform-tools
  4. Run the command adb shell pm setInstallLocation 2
  5. Go to settings in your mobile and check the "Move to SD card" option is enabled or not.


This tutorial has clear instructions to move the app to SD Card

http://mobile.tutsplus.com/tutorials/android/move-to-sd-card/

Also it has pointer to when to use the SD Card feature http://developer.android.com/guide/topics/data/install-location.html#ShouldNot

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜