0
List<AppWidgetProviderInfo> infos = mAppWidgetManager.getInstalledProviders();
int widgetId = mAppWidgetManager.getAppWidgetIds(infos.get(0).provider)[0];

Above code throws below security exception

java.lang.SecurityException: Package does not belong to 10069

Alternatively, if I launch the appwidgetpicker using action ACTION_APPWIDGET_BIND to retrieve the user permission,

ActivityNotFoundException: No Activity found to handle Intent { act=android.appwidget.action.APPWIDGET_PICK

again above exception(Only on android TV) is thrown:

However same code works on mobile, but not on android TV, so how do we build appwidgethost for android TV?

UPDATE 1: Following this also still throws same exception

UPDATE 2: Found bug on Android TV for the same

Mani
  • 2,599
  • 4
  • 30
  • 49

1 Answers1

0

ACTION_APPWIDGET_PICK and ACTION_APPWIDGET_BIND are not available in AndroidTV. The only way to allow your app to use widget is to use adb shell and execute

appwidget grantbind --package <your_package_name> --user 0

It is half solution, your users should have enough knowledge to be able to set up adb and run shell commands.

So what I'm doing in my application:

  1. I'm using custom widget picker dialog.
  2. When user picks a widget I check if ACTION_APPWIDGET_BIND is awailable
  3. If it is not I'm trying to use reflection to grant binding
  4. If reflection does not work I'm checking if there is su (root) available
  5. If it's not rooted I'm displaying a dialog explaining how to enable widgets manually via adb.

Not's not perfect but at least something.

dipcore
  • 190
  • 2
  • 8
  • BTW If you are system developer then you can just make your application system and add to manifest. – dipcore Nov 11 '18 at 18:19