How to hide Widget if Android API is not supported?


I am developing several widgets. One of them uses ListView, but ListView is not supported by Android 2.3.
So, if my application is installed in Android 2.3, then the widget with ListView should not be displayed in the list of widgets.
But my ListView widget appears in the widget list, and if I click on it, it will show me Force Closed.

That is why I want to hide these widgets from the list of widgets.
If anyone has any suggestions, please respond.

It shows me Force Closed and the following error for the widget
enter image description here

The same widget that I launch in Android 4.2, then shows me in the following list

enter image description here

Thanks.

+4
source share
2 answers

I am developing several widgets

No, you are developing several application widgets . Although I am sorry that these terms are confusing, it is very important for you to use the correct terminology in your question.

One of them uses ListView, but ListView is not supported by Android 2.3.

Correctly, ListView not supported in application widgets in Android 2.3 or lower.

So, if my application is installed in Android 2.3, then the widget with ListView should not be displayed in the list of widgets.

Step # 1: create a res/values/bools.xml that defines a logical resource with the name is_honeycomb and false .

Step # 2: create a res/values-v11/bools.xml defining another logical resource with the same name ( is_honeycomb ) and true

Step # 3: In your manifest, in the <receiver> element for the AppWidgetProvider that uses the ListView , add android:enabled="@bool/is_honeycomb" .

The net effect is that on Android 3.0+ devices your ListView widget will be available, but on Android 2.3 and lower devices it will not.

+12
source

ListView is supported in version 2.3. This is supported from Api level 1. And yes, ListView is only possible with application widgets from api level 11 (3.0).

 if(android.os.Build.VERSION.SDK_INT < 11) then hide your listview. 
0
source

All Articles