RemoteViewsFactory grantUriPermission 来获取数据
Posted
技术标签:
【中文标题】RemoteViewsFactory grantUriPermission 来获取数据【英文标题】:RemoteViewsFactory grantUriPermission to fetch data 【发布时间】:2013-07-13 00:58:02 【问题描述】:有一个带有 Listview 的 AppWidget,我想用 RemoteViewsService.RemoteViewsFactory 填充它。
我有以下错误
E/androidRuntime(1203): java.lang.SecurityException: 权限 拒绝:读取 com.crbin1.myapp.data.ProviderLTD uri content://com.crbin1.myapp.data.ProviderLTD/TB_WIDGET3P 来自 pid=413, uid=10013 要求提供者被导出,或者grantUriPermission()
如果我在清单中导出 ProviderLTD(我的内容提供商),它可以工作,但我想避免导出它。
另一个解决方案是grantUriPermission()。我在清单中将 grantUriPermissions 设置为 true,但现在我不明白我必须在代码中的哪个位置授予权限。
public class Widget3pService extends RemoteViewsService
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent)
return new StackRemoteViewsFactory(this.getApplicationContext(), intent);
class StackRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory
private List<ObjW3Task> mWidgetItems = new ArrayList<ObjW3Task>();
private Context mContext;
private int mAppWidgetId;
public StackRemoteViewsFactory(Context context, Intent intent)
mContext = context;
mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
public RemoteViews getViewAt(int position)
// use mWidgetItems to populate ListView
// fillInIntent for listeners
return myRemoteViews;
public void onDataSetChanged()
mWidgetItems = new ArrayList<ObjW3Task>();
// create mWidgetItems by accessing my ContentProvider class
【问题讨论】:
【参考方案1】:不确定这是否仍然相关;我发现它适用于我,通过设置“android:exported = true”:
<provider android:name="WeatherDataProvider" android:exported="true">
看到这个: Android Permission denial in Widget RemoteViewsFactory for Content
【讨论】:
以上是关于RemoteViewsFactory grantUriPermission 来获取数据的主要内容,如果未能解决你的问题,请参考以下文章
RemoteViewsFactory grantUriPermission 来获取数据
无法在 RemoteViewsFactory 中加载多个图像
RemoteViewsFactory 如何处理 Android 中的 ViewTypes?
调用 notifyAppWidgetViewDataChanged 后,在 RemoteViewsFactory 中不调用 onDataSetChanged