1.未接电话的产生

/*
* 未接来电不能用* Observer监听,不过当有新的未接来电时,系统会发送一个广播com.android
* .phone.NotificationMgr.MissedCall_intent(
* 锁屏上显示的未接来电数量就是通知监听这个广播实现的)
*/

因此基于广播----->/*
final IntentFilter filter = new IntentFilter();
filter.addAction("com.android.phone.NotificationMgr.MissedCall_intent");
final Application application = getApplication();
application.registerReceiver(
new BroadcastReceiver() {
@Override
public void onReceive(Context context,Intent intent) {
String action = intent.getAction();
if (action != null&& "com.android.phone.NotificationMgr.MissedCall_intent".equals(action)) {
int mMissCallCount = intent.getExtras().getInt("MissedCallNumber");
Toast.makeText(CallPhoneActivity.this, mMissCallCount+"",Toast.LENGTH_SHORT).show();
}
}
}, filter);*/--------------但是只能说亲测无效,未接受 .....


2.读取未接电话的个数

private int readMissCall() {
result = 0;
// Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI,
// new String[] { Calls.TYPE }, " type=? and new=?",
// new String[] { Calls.MISSED_TYPE + "", "1" }, "date desc");
Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI,
new String[] { Calls.TYPE }, " type=?",
new String[] { Calls.MISSED_TYPE + ""}, "date desc");


if (cursor != null) {
result = cursor.getCount();
cursor.close();
}
return result;
}

注意被注释掉的cursor的区别,限定了Call.New(android.provider.CallLog.Calls.NEW),会使得你过短时间,未接电话的读取个数清空,没有仔细研究过这个变量的具体定义,也懒得理解了..注意Call.New>0

若是想深入的了解,可以访问http://www.apihome.cn/api/android/CallLog.Calls.html.


3.未接电话相关信息的读取-----一些参数还得参照http://www.apihome.cn/api/android/CallLog.Calls.html

contactlist.clear();
final String[] projection = null;

final String selection = null;
final String[] selectionArgs = null;
final String sortOrder = android.provider.CallLog.Calls.DATE + " DESC";
Cursor cursor = null;
try {

cursor = getContentResolver().query(
                        Uri.parse("content://call_log/calls"), projection,
                        selection, selectionArgs, sortOrder);
                while (cursor.moveToNext()) {
                callName= cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
                    String callLogID = cursor.getString(cursor
                            .getColumnIndex(android.provider.CallLog.Calls._ID));
                    callNumber = cursor.getString(cursor
                            .getColumnIndex(android.provider.CallLog.Calls.NUMBER));
                    //需要对时间进行一定的处理
                    callDate = cursor.getString(cursor
                            .getColumnIndex(android.provider.CallLog.Calls.DATE));
                    long callTime = Long.parseLong(callDate);
                    SimpleDateFormat sdf = new SimpleDateFormat(
"M-dd HH:mm");
                    callDate = sdf.format(new Date(callTime));
                    
                    callType = cursor.getString(cursor
                            .getColumnIndex(android.provider.CallLog.Calls.TYPE));
                    String isCallNew = cursor.getString(cursor
                            .getColumnIndex(android.provider.CallLog.Calls.NEW));

//                    if (Integer.parseInt(callType) == (CallLog.Calls.MISSED_TYPE)
//                            && Integer.parseInt(isCallNew) > 0)  //通过call.new进行了限定,会对读取有一些问题,要删掉该限定
                    if (Integer.parseInt(callType) == (CallLog.Calls.MISSED_TYPE))
                    {
                    //textView.setText(callType+"|"+callDate+"|"+callNumber+"|"); 

//只是以最简单ListView显示联系人的一些数据----适配器的如何配置可查看http://blog.csdn.net/cl18652469346/article/details/52237637                   
                    contactlist.add(callName+"----"+callDate+"----"+callNumber+"----"+"callType:"+callType);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            finally {
                cursor.close();
            }.

}


未接电话的属性很多,可以自行查看已给出的链接,当然少不了数据格式的转换,比如Call.DATE(转换如上)

.

更多相关文章

  1. Android(安卓)Day01-电话拨号器案例&Android开发流程
  2. Android(安卓)挂断电话流程
  3. 数据存储之文件存储
  4. Android从assets和raw中读取txt文件
  5. android 之通话录音
  6. Android之--电话归属地的悬浮框的…
  7. 使用异步任务下载--疯狂android讲义实例
  8. android文件访问实例
  9. (Android(安卓)基础知识review)打电话

随机推荐

  1. (1) Android-5.0源码分析计划
  2. Android中得Static关键字
  3. 【整理】Android中使用XML自定义组件各种
  4. Android(安卓)Native 程序逆向入门(一)——
  5. 未来谁能引领Android大势
  6. php学习小结(php程序的运行原理、短标签的
  7. Android(安卓)代理模式
  8. Android(安卓)- 智能 wifi 插座控制开关
  9. Android(安卓)自动填写验证码
  10. 如何查看Android设备中的启动服务