我有带 2 张 SIM 卡的手机,我从通话记录中获得了所有字段和字段名称。从结果中,名为“smid”的字段显示了处理呼叫的 SIM 卡。
public void editToFile(){
File file = new File(Environment.getExternalStorageDirectory(), "fileOut.txt");
try{
BufferedWriter writer = new BufferedWriter(new FileWriter(file,true));
writer.write(mEdit.getText().toString());
writer.newLine();
writer.flush();
writer.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
public void getCallLogs(){
final String[] projection = null;
final String selection = null;
final String[] selectionArgs = null;
final String sortOrder = "DATE DESC";
Cursor cursor = this.getContentResolver().query(Uri.parse("content://call_log/calls"),projection,selection,selectionArgs,sortOrder);
int j=0;
//mEdit is EditText
mEdit.setText("");
if (cursor != null) {
int L=cursor.getColumnCount();
for(int i=0;i<L;i++)
mEdit.append(cursor.getColumnName(i) + "\t");
mEdit.append("\n");
while (cursor.moveToNext()) {
j++;
if(j>=5)
break;
for(int i=0;i<L;i++){
String callField = cursor.getString(i);
mEdit.append(callField + "\t");
}
mEdit.append("\n");
}
}
editToFile();
}