I have added 2 Widgets to my app. However if user moves the app to SD card on some Android versions, Widgets stop being available.
As a solution, I created a new small app which contains Widgets only. So users can move main app to SD card and have Widgets app in internal storage, to be able to use Widgets. Besides 2 main widgets, Widgets app has 2 more Widgets (4 in total). Those 2 extra Widgets are kind of beta Widgets. If I see one Widget is being used a lot, I’ll improve it and move it main package.
Problem arise when user does not move main app to SD card (or has an Android version which allows using Widgets from SD card) and if user installs Widgets app to have access those 2 extra Widgets. In that case, user will get 2 main widgets twice: one time from main app and another time from Widgets app.
What I want to do is disable those 2 Widgets from main app if I detect that Widgets app is installed too. That is to avoid having those 2 Widgets repeated.
I do know how to check from main app if Widgets app is installed. I just don’t know how to disable a Widget programmatically. Is that possible?
Use
PackageManagerandsetComponentEnabledSetting()to disable theAppWidgetProvider(s) by name, and they will no longer show up in the list.If the user already added those app widgets to their home screen, though, they will break, and the user may get confused.