我希望我的应用程序能够判断是否有未接来电,或者只是被解雇(当有来电时点击红色结束按钮)。
我是否使用 CallLog.Calls NEW 常量?
在您的清单文件中添加:
<uses-permission android:name="android.permission.READ_CONTACTS" />
并在您的活动中添加:
Uri allCalls = Uri.parse("content://call_log/calls");
Cursor c = getContentResolver().query(allCalls, null,
CallLog.Calls.NEW + " = ?", new String[] { "1" }, null);
c.moveToFirst();
String num= c.getString(c.getColumnIndex(CallLog.Calls.NUMBER));
String name= c.getString(c.getColumnIndex(CallLog.Calls.CACHED_NAME));
String duration = c.getString(c.getColumnIndex(CallLog.Calls.DURATION));
String type = c.getString(c.getColumnIndex(CallLog.Calls.TYPE));
Log.d("num", num);
Log.d("name", name);
Log.d("duration", duration);
Log.d("type", type);