Get the SIM number used on a call through the call log of Android

半腔热情 提交于 2019-12-06 15:32:46

I have phone with 2 SIM cards, and I got all fields from calllog, and field names. From results, field named "simid" shows which SIM card handled call.

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();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!