有一个我要用RemoteViewsService.RemoteViewsFactory填充的具有Listview的AppWidget。
我有以下错误
如果我在 list 中导出ProviderLTD(我的内容提供商),则可以使用,但我想避免导出它。
另一种解决方案是grantUriPermission()。我在 list 中将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
}
}
最佳答案
不知道这是否仍然有用;通过设置“android:exported = true”,我发现它对我有效:
<provider android:name="WeatherDataProvider" android:exported="true">
看到这个:
Android Permission denial in Widget RemoteViewsFactory for Content