I have tried the same thing as per the documentation. But nothing worked. Can someone say whether is this possible or not?
Thanks, Parveen On Feb 3, 6:56 pm, Matt <[email protected]> wrote: > Hi all. > > We would like to enable or disable widgets via code. When we say > "disable" we mean that awidgetwhich is registered in an application > should not show up in the list of widgets available to the user when > they try to add awidgetto their home screen. > > This question has been asked, unfortunately, many times without > answer. There was one response by Dianne Hackborn to a > separatewidgetquestion which suggested that it was possible to use the > package manager to disable widgets: > > PackageManager pm = context.getPackageManager(); > pm.setComponentEnabledSetting(new ComponentName( > "com.example.android.apis", > ".appwidget.ExampleBroadcastReceiver"), > PackageManager.COMPONENT_ENABLED_STATE_ENABLED, // or DISABLED > PackageManager.DONT_KILL_APP); > > This, however, does not work. Thewidgetcomponent will still appear > in the list of widgets. It may be that the AppWidgetService (located > in the Android source's Base.git at \src\base\services\java\com\android > \server), which loads the list of available widgets, caches this list > of available widgets. If that were the case, though, then the above > code which enables or disables thewidgetcomponent would work after a > device reset because there would be no cache; it does not. > > I have also tried looking into overriding some methods of the > AppWidgetProvider, such as filtering out any events. I don't think > this will go anywhere, because the AppWidgetService, which populates > the list, uses the Package Manager to find all components which catch > the ACTION_APPWIDGET_UPDATE action on startup and when a package is > added (i.e. a new app is installed). The only time that a provider is > removed from this list is on a ACTION_PACKAGE_REMOVED broadcast. > > So given that the providers will always be there, regardless of the > enabled/disabled state of the component, I have looked into the actual > list activity which is shown from the Launcher app when the user long- > clicks the desktop and adds awidget: AppWidgetPickActivity in > Settings.GIT in > com.android.settings. This, unfortunately, populates the list > directly from the AppWidgetService, without any filtering for the > component's enabled status: > void putInstalledAppWidgets(List<PickAdapter.Item> items) { > List<AppWidgetProviderInfo> installed = > mAppWidgetManager.getInstalledProviders(); > putAppWidgetItems(installed, null, items); > } > > I would love to see if anyone has overcome this hurdle. Perhaps I am > going about it the wrong way. All I want is to be able to remove awidgetfrom > the list of widgets available to the user when they try to > add awidgetto their home screen. > > Thanks, > -Matt -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

