java - how to determine whether last call was outgoing or incoming in android -
i using android call logs in app , determine whether last call incoming or out going call. have tried far int type gives me error android.database.cursorindexoutofboundsexception: index -1 requested, size of 284
cursor managedcursor = context.getcontentresolver().query( calllog.calls.content_uri,null, null,null, android.provider.calllog.calls.date + " desc"); int number = managedcursor.getcolumnindex( calllog.calls.number ); int duration1 = managedcursor.getcolumnindex( calllog.calls.duration); int type = integer.parseint(managedcursor.getstring(managedcursor.getcolumnindex(calllog.calls.type))); log.v("dialbroadcast receiver", "number is: " + type); if( managedcursor.movetofirst() == true ) { string phnumber = managedcursor.getstring( number ); callduration = managedcursor.getstring( duration1 ); string dir = null; sb.append( "\nphone number:--- "+phnumber +" \ncall duration in sec :--- "+callduration ); sb.append("\n----------------------------------"); log.i("*****call summary******","call duration is:-------"+sb); log.v("dialbroadcast receiver", "number is: " + callduration); }
you
int type = integer.parseint(managedcursor.getstring(managedcursor.getcolumnindex(calllog.calls.type)));
before chek if( managedcursor.movetofirst()){}
that's why exeption.
put line inside of if
or try method
private static string getcalldetails(context context) { stringbuffer stringbuffer = new stringbuffer(); cursor cursor = context.getcontentresolver().query(calllog.calls.content_uri, null, null, null, calllog.calls.date + " desc"); int number = cursor.getcolumnindex(calllog.calls.number); int type = cursor.getcolumnindex(calllog.calls.type); int date = cursor.getcolumnindex(calllog.calls.date); int duration = cursor.getcolumnindex(calllog.calls.duration); while (cursor.movetonext()) { string phnumber = cursor.getstring(number); string calltype = cursor.getstring(type); string calldate = cursor.getstring(date); date calldaytime = new date(long.valueof(calldate)); string callduration = cursor.getstring(duration); string dir = null; int dircode = integer.parseint(calltype); switch (dircode) { case calllog.calls.outgoing_type: dir = "outgoing"; break; case calllog.calls.incoming_type: dir = "incoming"; break; case calllog.calls.missed_type: dir = "missed"; break; } stringbuffer.append("\nphone number:--- " + phnumber + " \ncall type:--- " + dir + " \ncall date:--- " + calldaytime + " \ncall duration in sec :--- " + callduration); stringbuffer.append("\n----------------------------------"); } cursor.close(); return stringbuffer.tostring(); }
Comments
Post a Comment