Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing AppWidgets programmatically

I'm having the hardest time figuring out how to remove home screen AppWidget's programmatically (i.e. without the user actually dragging one into the trash). As an example, consider an app that can have multiple accounts, with any number of widgets for each account - once an account is removed, widget should be deleted as well.

I've tried following an obscure example from http://www.netmite.com/android/mydroid/cupcake/frameworks/base/services/java/com/android/server/AppWidgetService.java, but that doesn't seem to even trigger OnDeleted, much less remove the AppWidget from the home screen.

Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DELETED);
intent.setComponent(info.componentName); // references AppWidgetProvider's class
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
sendBroadcast(intent);

Does anyone have any advice on how this can be accomplished? An example would be the bee's knees. Thanks.

like image 435
Melllvar Avatar asked Dec 25 '10 23:12

Melllvar


People also ask

How do you delete app widgets?

Just touch and hold the widget you want to remove, and then tap Remove from Home.

How do I remove widgets from my lock screen Android?

Removing widgets To begin, you should see a lock towards the bottom of your screen. If you don't see it, pull the widget down until the lock is visible. Once you see the lock, press and hold the widget. Move it up to the “Remove” section, and it's gone from your lock screen!

What are application widgets 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).


1 Answers

You cannot add or remove app widgets from the home screen. Only the user can do that.

Any app widgets tied to a deleted account could show a different account, or adopt some "(account deleted)" look that would trigger the user to get rid of the app widget or reconfigure it.

like image 66
CommonsWare Avatar answered Oct 26 '22 17:10

CommonsWare