6

有一个带有 Listview 的 AppWidget,我想用 RemoteViewsService.RemoteViewsFactory 填充它。

我有以下错误

E/AndroidRuntime(1203): java.lang.SecurityException: Permission Denial: 从 pid=413,uid=10013 读取 com.crbin1.myapp.data.ProviderLTD uri content://com.crbin1.myapp.data.ProviderLTD/TB_WIDGET3P需要导出提供程序,或 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
        }
}
4

1 回答 1

-2

不确定这是否仍然相关;我发现它适用于我,通过设置“android:exported = true”:

<provider android:name="WeatherDataProvider" android:exported="true">

看到这个: Android Permission denial in Widget RemoteViewsFactory for Content

于 2015-07-07T03:46:44.003 回答