Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move to SD compatibility

Tags:

java

android

xml

I have an application for Android 2.1 and a I'd like to add move-to-sd support for devices with Android 2.2+.

I added that code:

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example2"
android:versionName="1.0"
android:versionCode="1"
android:installLocation="auto">
<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="8" />

But if I keep my project over the sdk level 7. I have an compile error

error: No resource identifier found for attribute 'installLocation' in package 'android'    AndroidManifest.xml /example2   line 2  Android AAPT Problem

And if I set it to level 8, it is possible that later when programming I introduce some code only available for sdk level 8+ and don't detect it.

Is there some way to fix that? Thanks

like image 547
Caroline Avatar asked Jun 08 '26 22:06

Caroline


1 Answers

If you're using Eclipse, you should be able to set the target SDK version through the Eclipse UI and it will recognize the installLocation attribute.

Project > Properties > Android > Project Build Target

As far as introducing code that only works in api level 8+ but setting a lower min SDK value, everything I've read online says only that there's no way to automatically protect yourself so at this point you just have to be more defensive and mindful with your code. You need to know which code requires an api level greater than your app's minimum and use Build.VERSION.SDK_INT against the Build.VERSION_CODES enum to check if it's ok to run that code and provide an optional approach if not.

like image 73
Rich Avatar answered Jun 10 '26 12:06

Rich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!