Call Logs For Dual Sim Android Device
I am using the below code to get the call log details which is working very fine for single SIM device, but the problem arises when it comes to the DUAL sim. I am trying to find wo
Solution 1:
You can use "sub_id" constant value to get information about sim card.
Full path to this value CallLog.Calls.SUB_ID = "sub_id", but is not available for public, so just hardcode in API before 21. For >=21 you can use PHONE_ACCOUNT_COMPONENT_NAME.
/**
* The subscription ID used to place this call. This is no longer used and has been
* replaced with PHONE_ACCOUNT_COMPONENT_NAME/PHONE_ACCOUNT_ID.
* For ContactsProvider internal use only.
* <P>Type: INTEGER</P>
*
* @Deprecated
* @hide
*/publicstaticfinalString SUB_ID = "sub_id";
Have a fun :)
Solution 2:
Here is the method which give you the All Call Logs Detail...
privatevoidgetCallDetails() {
StringBuffersb=newStringBuffer();
CursormanagedCursor= managedQuery( CallLog.Calls.CONTENT_URI,null, null,null, null);
intnumber= managedCursor.getColumnIndex( CallLog.Calls.NUMBER );
inttype= managedCursor.getColumnIndex( CallLog.Calls.TYPE );
intdate= managedCursor.getColumnIndex( CallLog.Calls.DATE);
intduration= managedCursor.getColumnIndex( CallLog.Calls.DURATION);
sb.append( "Call Details :");
while ( managedCursor.moveToNext() ) {
StringphNumber= managedCursor.getString( number );
StringcallType= managedCursor.getString( type );
StringcallDate= managedCursor.getString( date );
DatecallDayTime=newDate(Long.valueOf(callDate));
StringcallDuration= managedCursor.getString( duration );
Stringdir=null;
intdircode= 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;
}
sb.append( "\nPhone Number:--- "+phNumber +" \nCall Type:--- "+dir+" \nCall Date:--- "+callDayTime+" \nCall duration in sec :--- "+callDuration );
sb.append("\n----------------------------------");
}
managedCursor.close();
System.out.println(sb.toString());
}
And Also don't forgot to add these permissions in Manifest.Xml
<uses-permissionandroid:name="android.permission.READ_CALL_LOG" /><uses-permissionandroid:name="android.permission.WRITE_CALL_LOG" />
Post a Comment for "Call Logs For Dual Sim Android Device"