16读取通话记录
来源:互联网 发布:软件测试管理体系 编辑:程序博客网 时间:2024/05/17 07:49
所需权限
<!-- 获取拨打电话的记录权限 --> <uses-permission android:name="android.permission.READ_CALL_LOG"/>
layout 布局文件
mainActivity<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <ListView android:id="@+id/lv" android:layout_width="match_parent" android:layout_height="match_parent" /> <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="暂无数据" android:layout_centerInParent="true" android:textColor="#f00" android:textSize="30sp" /></RelativeLayout>
list填充文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/tv_number" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/tv_date" android:layout_width="wrap_content" android:layout_height="wrap_content" /></LinearLayout>
逻辑代码 mainActivity.java
package com.qf.day16_contentresolver_call_demo2;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.logging.SimpleFormatter;import android.net.Uri;import android.os.Bundle;import android.provider.CallLog;import android.app.Activity;import android.content.ContentResolver;import android.database.Cursor;import android.view.Menu;import android.widget.ListView;import android.widget.SimpleAdapter;import android.widget.TextView;/** * * 通话记录的数据 * * 1,获取ContentResolver对象 2,ContentResolver对象 通过Uri地址 获取数据 3,展示数据 * */public class MainActivity extends Activity { private ListView lv; private TextView tv; private ContentResolver contentResolver; //content://call_log/calls private Uri callUri = CallLog.Calls.CONTENT_URI; private String [] coumns = new String[]{CallLog.Calls._ID,CallLog.Calls.NUMBER,CallLog.Calls.DATE}; //存数据源的集合 private List<Map<String, Object>> list = new ArrayList<Map<String,Object>>(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv = (ListView) findViewById(R.id.lv); tv = (TextView) findViewById(R.id.tv); contentResolver = getContentResolver(); //解析器 通过Uri地址获取指定的字段项 Cursor cursor = contentResolver.query(callUri, coumns, null, null, null); while(cursor.moveToNext()){ Map<String, Object> map = new HashMap<String, Object>(); long id = cursor.getLong(cursor.getColumnIndex(CallLog.Calls._ID)); String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER)); long date = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE)); map.put("id", id); map.put("number", number); map.put("date", format.format(date)); list.add(map); } SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, list, R.layout.item, new String[]{"number","date"}, new int[]{R.id.tv_number,R.id.tv_date}); lv.setAdapter(adapter); //如果没有数据 展示VIew lv.setEmptyView(tv); }}
0 0
- 16读取通话记录
- iPhone上读取通话记录
- 读取通话记录的权限
- Android6.0读取通话记录
- android 读取手机通话记录
- Android端通话记录读取
- ContentProvider读取通讯录和通话记录
- 通话记录
- 通话记录
- android中读取联系人和通话记录
- android中读取联系人和通话记录
- android中根据电话号码读取通话记录表
- android读取联系人,短信,通话记录,IMSI
- 使用ContentResolver读取通话记录与短信记录
- Accessing iPhone Call History(读取iPhone通话记录)
- 判断用户是否拒绝读取短信,通讯录,通话记录的权限
- Android 6.0 通话记录生成保存和读取显示
- Android手机用户隐私获取,包括读取通讯录、读取通话记录、读取浏览器历史记录、读取手机短信
- 2016 ICPC 大连网络赛 HDU 5873 Football Games
- javaEE cookie保存中文时报错
- 华为交换机堆叠和集群配置
- 将本地代码上传到github
- Andorid中UI控件的详细介绍(四)——EditText
- 16读取通话记录
- 放肆的使用UIBezierPath和CAShapeLayer画各种图形(含仿微信视频眼镜Demo)
- 程序员必学,英文构词前缀
- Po学校Lesson12
- Linux网络配置
- 20个实用的正则表达式
- 查看日志
- 自定义Linux系统终端界面(Oh_My_Zsh)
- Windows下查看进程命令行参数