Binding AppWidgets to AppWidgetHost - Android

泄露秘密 提交于 2019-11-27 18:39:54

问题


When you normally want to add an AppWidget in Android there is a list where you need to pick one widget and it binds it to the home screen.

I'm trying to build an app which has its own appWidgetHost and specific App Widgets that I built for it.

I have two problems:

  1. I would like to be able to automatically bind a widget to my AppWidgetsHost without the user picking from the list.
  2. I want to make my own 'pick widgets list' and to load only widgets that I have created.

To make it simple; There is my app with my AppWidgets and I want full control in terms of binding a appWidget to the appWidgetHost etc.

3 people asked similar questions in Google forums:

  1. Link 1
  2. Link 2
  3. Link 3

The only answer I found to be a possibility is in link number 2. Paraneet (one of the repliers) said that you can install the app under /system/app instead of /data/app because some security issue. but I'm not sure if it is a reliable solution for production, and I would like to know more about the pros and cons of doing this.

Thanks, Shai.


回答1:


Unfortunatlly for you (and me), Paraneet is right.

binding appwidget is a sensitive action and thus, to avoid malware it requires the user's consent for the most part however if you install your app into the /system/data folder then you considered part of the OS and you are given a system permission which lets you decide to bind appwidget that you created without any user's involvement.




回答2:


In Android O, its possible to pin app widget programmatically. Just watch at example here

Also check out Google official documentation



来源:https://stackoverflow.com/questions/4258579/binding-appwidgets-to-appwidgethost-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!