Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

is it possible to show widget in "Add to home screen > Widgets" Dialog only for a certain android version without uploading two APKs and assigning to proper SDK version numbers?

like image 827
Cloudgiant Avatar asked Aug 15 '11 10:08

Cloudgiant


People also ask

What are the various android widgets available?

There are given a lot of android widgets with simplified examples such as Button, EditText, AutoCompleteTextView, ToggleButton, DatePicker, TimePicker, ProgressBar etc.

Is widget a view in android?

App widgets are miniature application views that can be embedded in other applications (such as the home screen) and receive periodic updates. These views are referred to as widgets in the user interface, and you can publish one with an app widget provider (or widget provider).

What are widgets in android user interface?

A widget is a View object that serves as an interface for interaction with the user. Android provides a set of fully implemented widgets, like buttons, checkboxes, and text-entry fields, so you can quickly build your UI. Some widgets provided by Android are more complex, like a date picker, a clock, and zoom controls.


2 Answers

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.

like image 185
Mark Avatar answered Sep 30 '22 16:09

Mark


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 widget packageManager.setComponentEnabledSetting(componentName, 1, 1);  //disable widget packageManager.setComponentEnabledSetting(componentName, 2, 1); 
like image 44
berlindev Avatar answered Sep 30 '22 15:09

berlindev