I am targeting 1.6 but I would like to have nice widget that can use stackview and other improvement Android SDK provides for widget if user is on 3.0 above device. and a plain widget on 1.6-2.3/
How should I do that two version of widget?
Thanks a lot
My recommendation:
Create two versions of the app widget and use the resource values method to enable/disable.
in res/values/bools.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="atLeastHoneycomb">false</bool>
<bool name="notHoneycomb">true</bool>
</resources>
in res/values-v11/bools.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="atLeastHoneycomb">true</bool>
<bool name="notHoneycomb">false</bool>
</resources>
in AndroidManifest.xml:
<receiver android:name="MyOldAppWidgetProvider"
android:enabled="@bool/notHoneycomb">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/example_oldappwidget_info" />
</receiver>
<receiver android:name="MyNewAppWidgetProvider"
android:enabled="@bool/atLeastHoneycomb">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/example_newappwidget_info" />
</receiver>
You can make sub folders in your res
directory API level specific by adding a suffix like -v11
.
For example, suppose your layout is called main.xml
. You can have your 1.6 - 2.3 main.xml
file in the layout
folder, and then put your new, fancy main.xml
file that includes your new widget in the layout-v11
folder. When using Honeycomb and up, the layout in the -v11
folder will be chosen when you refer to your file like R.layout.main
.
From there, you can have some logic in your activity that checks for the existence of your new widget object (or just check the Build.VERSION class) and branch accordingly.
For more details on this, check out the Qualifier name rules from the Android documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With