Search code examples
androidandroid-appwidget

Hide AppWidget from Selectionlist based on Android-Version


I wrote a Android Application which contains two homescreen widgets: One "classic" widget which uses features which were available since Android 1.6 and a "newstyle" widget which uses the features of Honeycomb and later to provide gesture support (StackView style).

The problem: How can I hide the Honeycomb-Widget from the Widget-Selection Dialog in Android Version before 3.0? Currently I catch this issue when the widget is added to the homescreen but it would be nicer if the widget wouldn't be avaialble at all.

The only solution which came to my mind: Provide two different APK's on the Android Market, one containing both widgets for Android>=3.0 and one only containing the classic one for <3.0. But this introduces additional maintenance which I want to avoid.


Solution

  • One "classic" widget which uses features which were available since Android 1.6

    I like to think of this as "retro". :-)

    How can I hide the Honeycomb-Widget from the Widget-Selection Dialog in Android Version before 3.0?

    Ah, there's a lovely trick for this that somebody pointed out in a tweet once:

    Step #1: Create res/values/bool.xml and define a @bool/v11 resource as false

    Step #2: Create res/values-v11/bool.xml and define @bool/v11 there as true

    Step #3: In the manifest, in the <provider> element for the Honeycomb app widget, use android:enabled=@bool/v11.

    Net: your app widget is only enabled on API Level 11 and higher.