CopyPastor

Detecting plagiarism made easy.

Score: 1.8084912070703671; Reported for: String similarity, Exact paragraph match Open both answers

Possible Plagiarism

Reposted on 2019-07-26
by Malwinder Singh

Original Post

Original - Posted on 2019-07-26
by Malwinder Singh



            
Present in both answers; Present only in the new answer; Present only in the old answer;

I used following code to get the calendar ID.
private fun getCalendarId(context: Context) : Long? { val projection = arrayOf(Calendars._ID, Calendars.CALENDAR_DISPLAY_NAME) var calCursor = context.contentResolver.query( Calendars.CONTENT_URI, projection, Calendars.VISIBLE + " = 1 AND " + Calendars.IS_PRIMARY + "=1", null, Calendars._ID + " ASC" ) if (calCursor != null && calCursor.count <= 0) { calCursor = context.contentResolver.query( Calendars.CONTENT_URI, projection, Calendars.VISIBLE + " = 1", null, Calendars._ID + " ASC" ) } if (calCursor != null) { if (calCursor.moveToFirst()) { val calName: String val calID: String val nameCol = calCursor.getColumnIndex(projection[1]) val idCol = calCursor.getColumnIndex(projection[0]) calName = calCursor.getString(nameCol) calID = calCursor.getString(idCol) Log.d("Calendar name = $calName Calendar ID = $calID") calCursor.close() return calID.toLong() } } return null }
So do not pass 0, 1 or 3 as Calendar ID. Use above function instead.
Also, check if Calendar ID is `null` and do not perform operations with it if it is `null`.

val calendarId = getCalendarId(context) if (calendarId != null) { //Call operations e.g.: Insert operation }

I was getting this issue and then I used following code to get the calendar ID.
private fun getCalendarId(context: Context) : Long? { val projection = arrayOf(Calendars._ID, Calendars.CALENDAR_DISPLAY_NAME) var calCursor = context.contentResolver.query( Calendars.CONTENT_URI, projection, Calendars.VISIBLE + " = 1 AND " + Calendars.IS_PRIMARY + "=1", null, Calendars._ID + " ASC" ) if (calCursor != null && calCursor.count <= 0) { calCursor = context.contentResolver.query( Calendars.CONTENT_URI, projection, Calendars.VISIBLE + " = 1", null, Calendars._ID + " ASC" ) } if (calCursor != null) { if (calCursor.moveToFirst()) { val calName: String val calID: String val nameCol = calCursor.getColumnIndex(projection[1]) val idCol = calCursor.getColumnIndex(projection[0]) calName = calCursor.getString(nameCol) calID = calCursor.getString(idCol) log("Calendar name = $calName Calendar ID = $calID") calCursor.close() return calID.toLong() } } return null }
So **do not pass 0, 1 or 3 as Calendar ID**. Use above function instead.

        
Present in both answers; Present only in the new answer; Present only in the old answer;