我知道如何获得未接来电提醒,但我不知道有多少次未接来电。那么如何计算这个未接来电的数量呢?
我在oncreate
中使用此代码:
TelephonyManager TelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
TelephonyMgr.listen(new TeleListener(),PhoneStateListener.LISTEN_CALL_STATE);
之后我使用此代码在未接来电时收到提醒:
class TeleListener extends PhoneStateListener {
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
if (ring == true && callReceived == false) {
missedcallno=incomingNumber;
Toast.makeText(getApplicationContext(),"It was A MISSED CALL:" + incomingNumber,Toast.LENGTH_LONG).show();
}
default:
break;
}
}
}
答案 0 :(得分:1)
检查此答案:https://stackoverflow.com/a/7621988/5275436
对于未接来电:
String[] projection = { CallLog.Calls.CACHED_NAME, CallLog.Calls.CACHED_NUMBER_LABEL, CallLog.Calls.TYPE };
String where = CallLog.Calls.TYPE+"="+CallLog.Calls.MISSED_TYPE;
Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI, projection,where, null, null);
c.moveToFirst();
Log.d("CALL", ""+c.getCount()); //do some other operation
并在清单中声明权限:
<uses-permission android:name="android.permission.READ_LOGS"></uses-permission>
有关选择和选择的详细信息
<强>选择强> 一个过滤器,声明要返回哪些行,格式化为SQL WHERE子句(不包括WHERE本身)。传递null将返回给定URI的所有行。
selectionArgs(where) 您可以在选择中包含?,它将被selectionArgs中的值替换,它们将在选择中出现。这些值将绑定为字符串。