is it possible to show widget only for a certain android version? is it possible to show widget only for a certain android version? android android

is it possible to show widget only for a certain android version?


I have a way to do it without any code e.g.:

In your res\values dir create a bools.xml file:

<?xml version="1.0" encoding="utf-8"?><resources> <bool name="honeycombOrAbove">false</bool></resources>

Create a values-v11 dir (for honeycomb or above values), copy the file to it and set the value to true.

Then in the manifest for the widget receiver use: android:enabled="@bool/honeycombOrAbove". I also used it in the configuration activity for the widget.

This means the widget is disabled at install time.


You can do it with the componentEnableSetting.Just disable the widget you don't want to have listed.The change will get active after phone-restart.

Context context = getApplicationContext();String str1 = "org.classname.to.widget.provider";ComponentName componentName = new ComponentName(context, str1);PackageManager packageManager = getPackageManager();int versioncode = Integer.valueOf(android.os.Build.VERSION.SDK);    //enable widgetpackageManager.setComponentEnabledSetting(componentName, 1, 1);//disable widgetpackageManager.setComponentEnabledSetting(componentName, 2, 1);