有一个带有Listview的AppWidget,我想用RemoteViewsService.RemoteViewsFactory填充。
我有以下错误
E / AndroidRuntime(1203):java.lang.SecurityException:Permission 拒绝:阅读com.crbin1.myapp.data.ProviderLTD uri 内容://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
}
}
答案 0 :(得分:-2)
不确定这是否仍然相关;通过设置&#34; android:exported = true&#34;:
,我发现它适用于我的<provider android:name="WeatherDataProvider" android:exported="true">
看到这个: Android Permission denial in Widget RemoteViewsFactory for Content