Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide Widget If not supported by Android API?

Tags:

android


I am developing multiple widgets, One of them uses ListView but ListView is not supported by Android 2.3.
So, if my app is installed in Android 2.3 at that time widget with ListView should not display in widget's list.
But my that widget with ListView is showing in widget's list and if i click on it than it shows me Force Closed.

That's why i want to hide Those Widgets from widget's list.
If any one has any suggestions please reply.

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

Same widget i run in Android 4.2 then it shows me as per following list

enter image description here

Thank you.

like image 339
Sunil Parmar Avatar asked Dec 16 '22 11:12

Sunil Parmar


1 Answers

I am developing multiple widgets

No, you are developing multiple app widgets. While I am sorry that the terms are confusing, it is very important for you to use the right terminology in your question.

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

Correct, ListView is not supported in app widgets in Android 2.3 or lower.

So, if my app is installed in Android 2.3 at that time widget with ListView should not display in widget's list.

Step #1: Create a res/values/bools.xml file, defining a boolean resource, with a name of is_honeycomb, and a value of false.

Step #2: Create a res/values-v11/bools.xml file, defining another boolean resource, with the same name (is_honeycomb), and a value of true

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

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

like image 163
CommonsWare Avatar answered Dec 29 '22 19:12

CommonsWare