Android从通话记录屏幕中提取条目 [英] Android pick up entry from call history screen
问题描述
使用下面从互联网获得的代码,我已经可以进入手机的通话记录屏幕。
I have been able to reach the call logs screen of my phone using the below code i got from internet. Is it possible to pick up the entry details, say number, time of call etc of single entry with on click ?
Intent showCallLog = new Intent();
showCallLog.setAction(Intent.ACTION_VIEW);
showCallLog.setType(CallLog.Calls.CONTENT_TYPE);
startActivity(showCallLog);
推荐答案
您不能使用意图选择单个条目
You can not use a intent to pick a single entry from logs.
但是您可以从db获取所有信息,并将它们显示在对话框列表
中,然后选择任意一个联系人
您想要的。
But you can get all info from db and show them into a dialog list
and then select any contact
you want.
在下面检查代码的工作方式。
Check below Code how it works.
注意:在清单中添加权限,如果您的 OS是6.0或更高版本
,则获得运行时权限来自用户的code>如何 此处。
Note: Add permission in manifest and If your OS is 6.0 or greater
then get runtime permission
from user how here.
<使用权限android:name = android.permission.READ_CALL_LOG />
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button ContactPickBtn = (Button) findViewById(R.id.btnPick);
ContactPickBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String[] strFields = {android.provider.CallLog.Calls._ID,
android.provider.CallLog.Calls.NUMBER,
android.provider.CallLog.Calls.CACHED_NAME,};
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
// Make you have call logs permissions
// if your os is 6.0 get call log permission at runtime.
final Cursor cursorCall = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI, strFields,
null, null, strOrder);
AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
builder.setTitle("Pick a contact");
android.content.DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface,
int item) {
cursorCall.moveToPosition(item);
Toast.makeText(
MainActivity.this,
cursorCall.getString(cursorCall
.getColumnIndex(android.provider.CallLog.Calls.NUMBER)),
Toast.LENGTH_LONG).show();
cursorCall.close();
return;
}
};
builder.setCursor(cursorCall, listener,
android.provider.CallLog.Calls.CACHED_NAME);
builder.create().show();
}
});
}
}
这篇关于Android从通话记录屏幕中提取条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!