6

have an AppWidget with a Listview that I want to populate with a RemoteViewsService.RemoteViewsFactory.

I have the following error

E/AndroidRuntime(1203): java.lang.SecurityException: Permission Denial: reading com.crbin1.myapp.data.ProviderLTD uri content://com.crbin1.myapp.data.ProviderLTD/TB_WIDGET3P from pid=413, uid=10013 requires the provider be exported, or grantUriPermission()

If I export ProviderLTD (my content provider) in manifest it works, but I'd like to avoid to export it.

The other solution is grantUriPermission(). I set grantUriPermissions to true in manifest, but now I don't understand where in my code I have to grant the permissions.

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
        }
}
crbin1
  • 2,219
  • 3
  • 22
  • 29

1 Answers1

-2

not sure if this is still relevant; I found it works on mine, by setting "android:exported = true":

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

See this: Android Permission denial in Widget RemoteViewsFactory for Content

Community
  • 1
  • 1
gan gary
  • 167
  • 1
  • 6