下载SQLiteSpy.exe
打开模拟器5554
打开perspective,选择DDMS
打开Devices,确认存在emulator-5554
打开file Explorer
打开data文件夹
打开data 文件夹
打开com.android.providers.telephony文件夹
打开database文件夹
导出mmssms.db 和 telephony.db
可用SQLiteSpy.exe打开mmssms.db 和 telephony.db
打开sms文件夹,可看到联系人记录
转换到java模式,打开manifest.xml
选择permission
添加用户权限userpermission
分别选择:
android.permission.READ_CONTACTS
android.permission.READ_SMS
android.permission.CALL_PHONE
此时可看到 manifest.xml 文件增加的内容为:
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
腾讯有多可怕:
如果想添加一个知道电话号码的QQ好友
先在手机上添加此联系人的电话
(可能需要等上两小时)PC上随便加个好友,出现好友推荐界面,第一行--第二行必定有新加入的手机电话号码的人员的QQ
微信、QQ、短信存在关键字过滤——智能手机基本无秘密所言(权限的允许)
打开file Explorer
打开data文件夹
打开data 文件夹
打开com.android.providers.contacts文件夹
打开database文件夹
导出contact2.db
用SQLiteSpy.exe打开contact2.db
provider是android的四大组件之一
provider是实现跨应用程序访问数据的组件
如:com.android.providers.media
不会自定义provider
provider的读取:getcontentResolver
URI 是URL 的超级
在URI 中头部可以自定义,不一定非得是http、ftp等协议
provider像是服务器
Resolver像是浏览器
靠 URI 的数据交互
项目经理、产品经理
48dp原则:通用
android:padding="4dp" 内缩
可用来设置某些文字在图片中的位置
基线对齐 android:layout_alignBaseline="@id/call_log_item_name"
可用DDMS中的emulator Control打电话给模拟器5554
Map 查找无序数据效率较高,支持put (key,Value)
装换为List是一个无序的链表
List
Set
1、在calllog日志中查看通话记录
2、通话记录的浏览(watch?)
3、通话记录的显示
4、可根据通话而改变的通话记录(通话次数+1及提前)
===============================
activity.java
package cpm.tarena.Phone;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class PhoneManagerActivity extends Activity {
//保存通话记录数据list
ContentResolver mContentResolver;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mContentResolver= this.getContentResolver();
// mContentResolver.insert(url, values);
// mContentResolver.delete(url, where, selectionArgs);
//mContentResolver.query(uri, projection, selection, selectionArgs, sortOrder);
//mContentResolver.query(CallLog.CONTENT_URI, null, "name== '?' and type == ?", String[] ("abc","1"), "date");
//游标,读取游标数据
Cursor mCursor= mContentResolver.query(CallLog.Calls.CONTENT_URI, null, null, null, "date");
String[] colsName = mCursor.getColumnNames();
while(mCursor.moveToNext()){
for(int i=0; i<colsName.length; i++){
Log.i("CallLog",colsName[i]+":"+mCursor.getString(i) );
}
Log.i("CallLog", "-------------------");
//String callNumber = mCursor.getString(mCursor.getColumnIndex("number"));
}
}
}
添加联系人,并打出电话
可查看log日志
可新建一个CallLog,标签设为CallLog
可看到通话的联系人姓名、电话号码、通话时长等
==========================================
2、通话记录的浏览
activity.java
package cpm.tarena.Phone;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class PhoneManagerActivity extends Activity {
//保存通话记录数据list
ContentResolver mContentResolver;
ArrayList<MyCallLog> mCallLogListData = new ArrayList<MyCallLog>();
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mContentResolver= this.getContentResolver();
// mContentResolver.insert(url, values);
// mContentResolver.delete(url, where, selectionArgs);
//mContentResolver.query(uri, projection, selection, selectionArgs, sortOrder);
//mContentResolver.query(CallLog.CONTENT_URI, null, "name== '?' and type == ?", String[] ("abc","1"), "date");
Cursor mCursor= mContentResolver.query(CallLog.Calls.CONTENT_URI,new String[] {"_id","date","duration","name","number","type"} , null, null, "date desc");
String[] colsName = mCursor.getColumnNames();
while(mCursor.moveToNext()){
MyCallLog nowCallLogs = new MyCallLog();
nowCallLogs.setId(mCursor.getInt(0));
nowCallLogs.setDate(mCursor.getLong(1));
Date nowdate = new Date(0);
if(nowdate.getTime() - (60*1000) < nowCallLogs.getDate()){
nowCallLogs.setDateFormat("刚刚");
else if (nowdate.getTime() - (60*1000*60) < nowCallLogs.getDate()){
nowCallLogs.setDateFormat("n分钟");
else if (nowdate.getTime() - (60*1000*60*24) < nowCallLogs.getDate()){
nowCallLogs.setDateFormat("今天");
else if (nowdate.getTime() - (60*1000*60*24*2) < nowCallLogs.getDate()){
nowCallLogs.setDateFormat("昨天");
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd hh:mm");
nowCallLogs.setDateFormat(sdf.format(new Date(nowCallLogs.getDate())));
nowCallLogs.setDuration(mCursor.getLong(2));
nowCallLogs.setName(mCursor.getString(3));
nowCallLogs.setTelNumber(mCursor.getString(4));
nowCallLogs.setType(mCursor.getInt(5));
mCallLogListData.add(nowCallLogs);
mCallLogListData.toString();
}
----------------------------
MyCallLog.java
package cpm.tarena.Phone;
import java.util.ArrayList;
import android.content.ContentResolver;
import android.database.Cursor;
import android.provider.CallLog;
import android.text.format.DateFormat;
import android.util.Log;
public class MyCallLog {
//id、时间、时长、打进 打出 未接(1 2 3)、号码。。。
private int id;
private long duration;
private long date;
private int type;
private String number;
private String name;
private String dateFormat;
public String getDateFormat() {
return dateFormat;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public long getDuration() {
return duration;
}
public void setDuration(long duration) {
this.duration = duration;
}
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getTelNumber() {
return number;
}
public void setTelNumber(String telNumber) {
this.number = telNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
===========================================
3、通话记录的显示
PhoneManager.java
package cpm.tarena.Phone;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
public class PhoneManagerActivity extends Activity {
//保存通话记录数据list
ContentResolver mContentResolver;
ArrayList<MyCallLog> mCallLogListData = new ArrayList<MyCallLog>();
ListView mCallLogListView;
CalllogAdapter mCallLogAdapter;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mContentResolver= this.getContentResolver();
// mContentResolver.insert(url, values);
// mContentResolver.delete(url, where, selectionArgs);
//mContentResolver.query(uri, projection, selection, selectionArgs, sortOrder);
//mContentResolver.query(CallLog.CONTENT_URI, null, "name== '?' and type == ?", String[] ("abc","1"), "date");
Cursor mCursor= mContentResolver.query(CallLog.Calls.CONTENT_URI,
new String[] {"_id","date","duration","name","number","type"} , null, null, "date desc");
String[] colsName = mCursor.getColumnNames();
while(mCursor.moveToNext()){
MyCallLog nowCallLogs = new MyCallLog();
nowCallLogs.setId(mCursor.getInt(0));
nowCallLogs.setDate(mCursor.getLong(1));
Date nowdate = new Date(0);
if(nowdate.getTime() - (60*1000) < nowCallLogs.getDate()){
nowCallLogs.setDateFormat("刚刚");
else if (nowdate.getTime() - (60*1000*60) < nowCallLogs.getDate()){
nowCallLogs.setDateFormat("n分钟");
else if (nowdate.getTime() - (60*1000*60*24) < nowCallLogs.getDate()){
nowCallLogs.setDateFormat("今天");
else if (nowdate.getTime() - (60*1000*60*24*2) < nowCallLogs.getDate()){
nowCallLogs.setDateFormat("昨天");
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd hh:mm");
nowCallLogs.setDateFormat(sdf.format(new Date(nowCallLogs.getDate())));
nowCallLogs.setDuration(mCursor.getLong(2));
nowCallLogs.setName(mCursor.getString(3));
nowCallLogs.setTelNumber(mCursor.getString(4));
nowCallLogs.setType(mCursor.getInt(5));
mCallLogListData.add(nowCallLogs);
mCallLogListData.toString();
mCallLogListView = (ListView) findViewById(R.id.call_log_listview);
mCallLogAdapter = new CalllogAdapter(this, mCallLogListData, R.layout.calllog_list_item_layout);
mCallLogListView.setAdapter(mCallLogAdapter);
}
------------------------------------
MyCalllog.java
package cpm.tarena.Phone;
import java.util.ArrayList;
import android.content.ContentResolver;
import android.database.Cursor;
import android.provider.CallLog;
import android.text.format.DateFormat;
import android.util.Log;
public class MyCallLog {
ArrayList<CallLog> mCallLogs= new ArrayList<CallLog>();
//id、时间、时长、打进 打出 未接(1 2 3)、号码。。。
private int id;
private long duration;
private long date;
private int type;
private String number;
private String name;
private String dateFormat;
public String getDateFormat() {
return dateFormat;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public long getDuration() {
return duration;
}
public void setDuration(long duration) {
this.duration = duration;
}
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getTelNumber() {
return number;
}
public void setTelNumber(String telNumber) {
this.number = telNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
------------------------------------------------------------
CalllogAdaper.java
package cpm.tarena.Phone;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class CalllogAdapter extends BaseAdapter{
Context mcontext;
List<MyCallLog> mcalllogListData;
int mitemLayoutId;
LayoutInflater mLayoutInflater;
public CalllogAdapter(
Context context,
List<MyCallLog> calllogListData,
int itemLayoutId)
{
mcontext= context;
mcalllogListData= calllogListData;
mitemLayoutId= itemLayoutId;
mLayoutInflater = LayoutInflater.from(mcontext);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mcalllogListData.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mcalllogListData.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return mcalllogListData.get(position).hashCode();
}
@Override
public View getView(int position,
View convertView,
ViewGroup parent)
{
//判断是否实例化Item
if(convertView==null ){
convertView = mLayoutInflater.inflate(mitemLayoutId, null);
}
//找到需要修改的控件
TextView nameTv =(TextView) convertView.findViewById(R.id.call_log_item_name);
TextView numberTv =(TextView) convertView.findViewById(R.id.call_log_item_number);
TextView dateTv =(TextView) convertView.findViewById(R.id.call_log_item_date);
TextView typeTv =(TextView) convertView.findViewById(R.id.call_log_item_type);
//设置控件要显式的内同
//CalllogAdapter nowCallLog = mcalllogListData.get(position);
MyCallLog nowCallLogs = mcalllogListData.get(position);
if(null != nowCallLogs.getName()){
nameTv.setText(nowCallLogs.getName());
}
else{
nameTv.setText("未知");
}
if(null != nowCallLogs.getTelNumber()){
numberTv.setText(nowCallLogs.getTelNumber());
}
else{
numberTv.setText("保密");
}
dateTv.setText(nowCallLogs.getDateFormat());
switch (nowCallLogs.getType()) {
case 1:
//打进
typeTv.setBackgroundResource(R.drawable.icon_log_incoming);
break;
case 2:
//打出
typeTv.setBackgroundResource(R.drawable.icon_log_outgoing);
break;
case 3:
//未接
typeTv.setBackgroundResource(R.drawable.icon_log_missed);
break;
}
// TODO Auto-generated method stub
return convertView;
}
}
------------------------------------------------------------------------
calllog_list_item_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:orientation="vertical"
android:background="#ccfcfc">
<ImageView
android:id="@+id/call_log_item_photo"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/default_thumbnail"
android:background="#00f"
android:padding="4dp"/>
<TextView
android:id="@+id/call_log_item_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/icon_log_missed"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="5"
android:textColor="#000"
android:gravity="center"
android:paddingRight="24dp"/>
<TextView
android:id="@+id/call_log_item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="张三"
android:paddingLeft="4dp"
android:paddingTop="4dp"
android:textSize="18dp"
android:textColor="#000"
android:layout_toRightOf="@id/call_log_item_photo"
android:layout_alignTop="@id/call_log_item_name"/>
<TextView
android:id="@+id/call_log_item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="13717843343"
android:textSize="16dp"
android:paddingLeft="4dp"
android:layout_toRightOf="@id/call_log_item_name"
android:layout_alignBaseline="@id/call_log_item_name"/>
<TextView
android:id="@+id/call_log_item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3小时前"
android:textSize="16dp"
android:paddingBottom="2dp"
android:paddingLeft="4dp"
android:layout_toRightOf="@id/call_log_item_photo"
android:layout_alignBottom="@id/call_log_item_photo"/>
</RelativeLayout>
----------------------------------------------------------------------
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@+id/call_log_listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
<LinearLayout
android:visibility="gone"
android:id="@+id/keyboard_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#fcfcfc"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/keyboard_line_bg" >
<ImageButton
android:id="@+id/hide_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#0000"
android:src="@drawable/keyboard_hide" />
<ImageButton
android:id="@+id/del_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#0000"
android:src="@drawable/keyboard_backspace" />
<Button
android:id="@+id/call_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/del_button"
android:layout_toRightOf="@id/hide_button"
android:background="@drawable/dial_call_bg"
android:ellipsize="start"
android:text="139111111"
android:textColor="#fff"
android:textSize="18sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/key_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/key_bg_s"
android:src="@drawable/keyboard_1" />
<ImageButton
android:id="@+id/key_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/key_bg_s"
android:src="@drawable/keyboard_2" />
<ImageButton
android:id="@+id/key_3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/key_bg_s"
android:src="@drawable/keyboard_3" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/key_4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/key_bg_s"
android:src="@drawable/keyboard_4" />
<ImageButton
android:id="@+id/key_5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/key_bg_s"
android:src="@drawable/keyboard_5" />
<ImageButton
android:id="@+id/key_6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/key_bg_s"
android:src="@drawable/keyboard_6" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/key_7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/key_bg_s"
android:src="@drawable/keyboard_7" />
<ImageButton
android:id="@+id/key_8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/key_bg_s"
android:src="@drawable/keyboard_8" />
<ImageButton
android:id="@+id/key_9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/key_bg_s"
android:src="@drawable/keyboard_9" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/key_star"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/key_bg_s"
android:src="@drawable/keyboard_star" />
<ImageButton
android:id="@+id/key_0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/key_bg_s"
android:src="@drawable/keyboard_0" />
<ImageButton
android:id="@+id/key_hash"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/key_bg_s"
android:src="@drawable/keyboard_hash" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
=============================================
4、可根据通话而改变的通话记录(通话次数+1及提前)
PhoneManagerActivity.java
package cpm.tarena.Phone;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CallLog;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
public class PhoneManagerActivity extends Activity {
//保存通话记录数据list
ContentResolver mContentResolver;
ArrayList<MyCallLog> mCallLogListData = new ArrayList<MyCallLog>();
LinkedHashMap<String, MyCallLog> mCallLogMapData = new LinkedHashMap<String, MyCallLog>();
ListView mCallLogListView;
CalllogAdapter mCallLogAdapter;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mCallLogListView = (ListView) findViewById(R.id.call_log_listview);
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
mContentResolver= this.getContentResolver();
Cursor mCursor= mContentResolver.query(CallLog.Calls.CONTENT_URI,
new String[] {"_id","date","duration","name","number","type"} , null, null, "date desc");
String[] colsName = mCursor.getColumnNames();
while( mCursor.moveToNext() ){
MyCallLog nowCallLogs = new MyCallLog();
nowCallLogs.setId(mCursor.getInt(0));
nowCallLogs.setDate(mCursor.getLong(1));
Date nowdate = new Date(0, 0, 0) ;
Date today = new Date(nowdate.getYear(), nowdate.getMonth(),nowdate.getDay());
// 在1分钟内显示刚刚
// 60分钟内显示n分钟
// 超过60分钟,还在今天显示n小时之前
// 不在今天,在昨天24小时内显示 昨天 : 时分
// 超过昨天显示前天:时分
// 超过前天显示 月/日 时分
if(nowdate.getTime() - (60*1000) < nowCallLogs.getDate()){
nowCallLogs.setDateFormat("刚刚");
else if (nowdate.getTime() - (60*1000*60) < nowCallLogs.getDate()){
nowCallLogs.setDateFormat("n分钟");
else if (nowdate.getTime() - (60*1000*60*24) < nowCallLogs.getDate()){
nowCallLogs.setDateFormat("今天");
else if (nowdate.getTime() - (60*1000*60*24*2) < nowCallLogs.getDate()){
nowCallLogs.setDateFormat("昨天");
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd hh:mm");
nowCallLogs.setDateFormat(sdf.format(new Date(nowCallLogs.getDate())));
nowCallLogs.setDuration(mCursor.getLong(2));
nowCallLogs.setName(mCursor.getString(3));
nowCallLogs.setTelNumber(mCursor.getString(4));
nowCallLogs.setType(mCursor.getInt(5));
//mCallLogListData.add(nowCallLogs);
MyCallLog mapCallLog = mCallLogMapData.get(nowCallLogs.getTelNumber());
if(null != mapCallLog){
int callCount = mapCallLog.getCount()+1;
mapCallLog.setCount(callCount);
}
else{
nowCallLogs.setCount(1);
mCallLogMapData.put(nowCallLogs.getTelNumber(), nowCallLogs);
}
mCallLogListData = new ArrayList<MyCallLog>(mCallLogMapData.values());
mCallLogListData.toString();
// mCallLogListView = (ListView) findViewById(R.id.call_log_listview);
mCallLogAdapter = new CalllogAdapter(this, mCallLogListData, R.layout.calllog_list_item_layout);
mCallLogListView.setAdapter(mCallLogAdapter);
mCallLogListView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> listView, View itemView,
int position, long itemId) {
// TODO Auto-generated method stub
MyCallLog nowCallLog = (MyCallLog)listView.getItemAtPosition(position);
// 获得要拨打出去的电话
String number = nowCallLog.getTelNumber();
Uri callUri = Uri.parse("tel:" + number);
Intent callIntent = new Intent();
callIntent.setAction(Intent.ACTION_CALL);
callIntent.setData(callUri);
startActivity(callIntent);
}
}//onResume的end
}
----------------------------------------------
MyCallLog.java
package cpm.tarena.Phone;
import java.util.ArrayList;
import android.content.ContentResolver;
import android.database.Cursor;
import android.provider.CallLog;
import android.text.format.DateFormat;
import android.util.Log;
public class MyCallLog {
ArrayList<CallLog> mCallLogs= new ArrayList<CallLog>();
//id、时间、时长、打进 打出 未接(1 2 3)、号码。。。
private int id;
private long duration;
private long date;
private int type;
private String number;
private String name;
private String dateFormat;
private int count;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getDateFormat() {
return dateFormat;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public long getDuration() {
return duration;
}
public void setDuration(long duration) {
this.duration = duration;
}
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getTelNumber() {
return number;
}
public void setTelNumber(String telNumber) {
this.number = telNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
------------------------------------------
CalllogAdapter.java
package cpm.tarena.Phone;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class CalllogAdapter extends BaseAdapter{
Context mcontext;
List<MyCallLog> mcalllogListData;
int mitemLayoutId;
LayoutInflater mLayoutInflater;
public CalllogAdapter(
Context context,
List<MyCallLog> calllogListData,
int itemLayoutId)
{
mcontext= context;
mcalllogListData= calllogListData;
mitemLayoutId= itemLayoutId;
mLayoutInflater = LayoutInflater.from(mcontext);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mcalllogListData.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mcalllogListData.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return mcalllogListData.get(position).hashCode();
}
@Override
public View getView(
int position,
View convertView,
ViewGroup parent)
{
//判断是否实例化Item
if(convertView==null ){
convertView = mLayoutInflater.inflate(mitemLayoutId, null);
}
//找到需要修改的控件
TextView nameTv =(TextView) convertView.findViewById(R.id.call_log_item_name);
TextView numberTv =(TextView) convertView.findViewById(R.id.call_log_item_number);
TextView dateTv =(TextView) convertView.findViewById(R.id.call_log_item_date);
TextView typeTv =(TextView) convertView.findViewById(R.id.call_log_item_type);
//设置控件要显式的内容
MyCallLog nowCallLogs = mcalllogListData.get(position);
//显示联系人名称
if(null != nowCallLogs.getName()){
nameTv.setText(nowCallLogs.getName());
}
else{
nameTv.setText("未知");
}
//显示联系人电话号码
if(null != nowCallLogs.getTelNumber()){
numberTv.setText(nowCallLogs.getTelNumber());
}
else{
numberTv.setText("保密");
}
//显示通话记录时间
dateTv.setText(nowCallLogs.getDateFormat());
//显示通话类型(1:打进、2:打出、3:未接)
switch (nowCallLogs.getType()) {
case 1:
//打进
typeTv.setBackgroundResource(R.drawable.icon_log_incoming);
break;
case 2:
//打出
typeTv.setBackgroundResource(R.drawable.icon_log_outgoing);
break;
case 3:
//未接
typeTv.setBackgroundResource(R.drawable.icon_log_missed);
break;
}
//显示相同联系人的通话次数
typeTv.setText(""+nowCallLogs.getCount());
// TODO Auto-generated method stub
return convertView;
}
}
-------------------------------------------
实现效果为:
- android实习程序6——拨号通话
拨号通话 ListView GridView AdapterView 在路径android-sdkr16\android-sdkr16\platform-tools确认存在adb.exe 下载youl ...
- 建立一个类似于天眼的Android应用程序:第4部分 - 持久收集联系人,通话记录和短信(SMS)
建立一个类似于天眼的Android应用程序:第4部分 - 持久收集联系人,通话记录和短信(SMS) 电话黑客android恶意软件编程黑客入侵linux 随着我们继续我们的系列,AMUNET应用程序变 ...
- Mono for Android (2)-- Android应用程序初认识
一:日志记录 先添加using Android.Util; 在该命名控件下有log类 Log.Info("HA", "End onCreate"); //记录消 ...
- android 应用程序框架
携带Android软件开发时间,由开发商开发Android应用程序是通过应用程序框架和Android底层交互,因此,发展以达到最大的部分是应用程序框架. 应用集成框架 那里4一个重要组成部分,以下. ...
- 与Android应用程序相关的文件目录都有哪些?(转载)
与Android应用程序相关的文件目录都有哪些? | 浏览:1312 | 更新:2014-09-28 19:43 | 标签:android 一.方法介绍: 每个Android应用程序都可以通过Co ...
- [转]Android应用程序框架思路整理
一.一般Android应用程序架构(Book,购彩,Market). 普通的应用程序由于只需要用到Android的联网与显示的功能,所以应用程序大体上是呈现为UI(Activities)与网络(Net ...
- android的程序运行数据存放在哪里?
Android应用开发中,给我们提供了5种数据的存储方式1 使用SharedPreferences存储数据2 文件存储数据3 SQLite数据库存储数据4 使用ContentProvider存储数据5 ...
- Android卸载程序之后跳转到指定的反馈页面
一个应用被用户卸载肯定是有理由的,而开发者却未必能得知这一重要的理由,毕竟用户很少会主动反馈建议,多半就是用得不爽就卸,如果能在被卸载后获取到用户的一些反馈,那对开发者进一步改进应用是非常有利的.目前 ...
- 使用 Eclipse PhoneGap 构建 Android 应用程序入门
Eclipse 是一种支持多种技术的开源集成开发环境 (IDE),但本文重点介绍 Java 支持,这也是 Android 应用程序的“母语”.Android 是 Google 发布的开源移动操作系统. ...
随机推荐
- Django中国|Django中文社区——python、django爱好者交流社区
Django中国致力于成为Python和Django框架等技术的中文开发者学习交流平台. 内容涵盖python教程.python基础.Django教程.python入门.web.py教程.linux教 ...
- 使用 windows 计划任务播放音乐文件
这个问题网上可以搜到很多答案,但都有一些小细节没有交代,而我平时又很少使用计划任务,所以配置中出了点问题,特此备注. 1.播放器 检查当前系统下目标文件的默认播放器是什么,并且确保可以运行. 比如首次 ...
- BZOJ 1571: [Usaco2009 Open]滑雪课Ski
Description Farmer John 想要带着 Bessie 一起在科罗拉多州一起滑雪.很不幸,Bessie滑雪技术并不精湛. Bessie了解到,在滑雪场里,每天会提供S(0<=S& ...
- maven 根据不同的环境打war包-->资源文件的处理方式
发现犯的错误: 1. 指定了testResource 文件夹与resource 为同一个文件夹.导致不论在resource 里面如何过滤文件,都不起作用.资源文件本来就是共享的.不必这样指定. 2. ...
- android中handler中 obtainmessge与New message区别
obtainmessage()是从消息池中拿来一个msg 不需要另开辟空间new new需要重新申请,效率低,obtianmessage可以循环利用: //use Handler.obtainMess ...
- 行为树实现AI逻辑
http://blog.csdn.net/kenkao/article/details/6099966 http://www.aisharing.com/archives/99 http://www. ...
- C#程序集使用强名字(Strong Name)签名/强名称签名
强名称签名的方法: 强签名: 1. 可以将强签名的dll注册到GAC,不同的应用程序可以共享同一dll. 2. 强签名的库,或者应用程序只能引用强签名的dll,不能引用未强签名的dll,但是未强签名的 ...
- 【HDOJ】2206 IP的计算
题目很简单,情况有很多种. #include <stdio.h> #include <string.h> ]; int isIPaddr(char buf[]) { int i ...
- 便利的html5 之 required、number 、pattern
html5对于表单验证提供了很多自识别功能,非常的便利. 看代码, <!--head start--> <include file="Public:head" / ...
- [FJSC2014]滑行
[题目描述] 首长NOI惨跪,于是去念文化课了.现在,他面对一道物理题. 现在有一个小滑块可以在地面上滑行,地面上被划分成不同的区域,使得小滑块在不同的区域内部有一个不同的速度上限. 小滑块在(0,0 ...