开发者

Move to SD card on Android

Some of my users (very few) are unable to move my app to the SD card. Even though they have android 2.2 and up and I enabled it 开发者_开发知识库in the manifest. The button Move to SD is turned off. For example, LG Optimus V for Virgin Mobile.

I've tested on phones like Nexus One and it works perfect, for Android 2.2 (Froyo) and up.

I understand that the coding for "Move to SD card" option is in the AndroidManifest.

android:installLocation="auto".

Is there a third party that is blocking it, or am I missing something?


InstallLocation is working on version Android 2.2 (Froyo) and above. Below they are not supporting it and will also give permission in Manifest INSTALL_LOCATION_PROVIDER.


If you are using Eclipse, just click on the Android Device Manager icon. Then click on the Android Device Manager tab. If you've already created an AVD, just select it. Then click on the "Edit Button" on the right side. Then locate where the SD card is and then change size to your preferred number, "e.g: 256 or 512 or 1024" and make sure that you have enough "Internal storage capacity". Click on the OK button.

Now go to the "Run Configuration" and start your AVD emulator. In the setting of AVD you should see that your SD card is "Mounted".

This should work.

If you want to add a file or folder or move an application into your SD card, just do the following:

Steps:

  1. Open your Android application's source code file with a text or programming editor. 2) Browse to the location in the source code where you wish to call the function that writes a file to the device's external storage. 3) Insert this single line of code to check for the SD card:

     File sdCard = Environment.getExternalStorageDirectory();
    
  2. Insert these lines of code to set the directory and file name:

     File dir = new File (sdcard.getAbsolutePath() + "/folder1/folder2");
     dir.mkdirs();
     File file = new File(dir, "example_file");
    
  3. Replace "/folder1/folder2" in the above code with the actual path where you intend to save the file. This should be a location in which you normally save your application files. Also, change the "example_file" value to the actual file name you wish to use.

  4. Insert the following line of code to output the file to the SD card:

     FileOutputStream f = new FileOutputStream(file);
    
  5. Save the file, then compile it and test the application using the Android emulator software or the device.

This will work!!! ;-)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜