I'm currently implementing the calendar provider however i've stumbled upon a minor error that i'd like to prevent.
ContentResolver contentResolver = getContentResolver();
ContentValues contentValues = new ContentValues();
....
Uri uri = contentResolver.insert(CalendarContract.Events.CONTENT_URI, contentValues); // Error pops here
"Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission
) or explicitly handle a potential `SecurityException"
What is the best method to prevent this error?
Any help will be appreciated.
Your targetSdkVersion is 23 or higher, just reduce it
You can always add throws SecurityException to the method and take care of the caught exception further upstream. Furthermore, I would recommend using this library https://github.com/tbruyelle/RxPermissions if you interested in using reactivex methodology to deal with permissioning.
Handle android permission first , check if they are available , if not you can request them as shown below
proceed with your functionality only if permissions are available