标签:tap color 软件 api ring sel 一个 .exe move
项目的Github地址:
采用基于git的多人协作开发模式
软件采用mvc设计模式,前端这么艺术的事我不太懂,交给斌豪同学去头疼了。第一轮先实现查询通话记录返回对应号码(亲情账号?pm的需求分析还没出来,还不是很清楚具体操作)上一次的通话时间。
API接口:
那么我写的功能就要脱离activity了。那么首先要做的就是获取全局Context。
实现的话挺简单的,就是要先理解Context的含义,我是通过看http://www.jianshu.com/p/94e0f9ab3f1d(Context都没弄明白,还怎么做Android开发?)这篇简书理解的。不是主要玩安卓开发的,碰到安卓这些特性还是挺头疼的。实现方法就是写一个Application的子类,然后修改AndroidMainifest.xml。公式化的方法了。实现后就可以通过调用,MyApplication.getContext()获取全局Context了,具体代码如下:
1 public class MyApplication extends Application { 2 private static Context context; 3 @Override 4 public void onCreate(){ 5 context=getApplicationContext(); 6 } 7 public static Context getContext() { 8 return context; 9 } 10 }
1 android:name=".MyApplication"//在<application></application>中插入
然后就是建立数据库了,用安卓内置的SQLite。讲道理,一般用Litepal来操纵数据库会简单很多,但话又说回来了,我又不是主玩安卓开发的,学习这东西还是从底层开始比较容易懂,所以这里用SQLiteDatabase来操控数据库。
建立数据库:公式化的方法,两个方法是重写SQLiteOpenHelper里的方法,一个用在创建整个数据库的时候,一个用在给数据库升级的时候(比如插入新表)。
1 public class LastTimeDatabaseHelper extends SQLiteOpenHelper{ 2 public static final String CREATE_KITH_AND_KIN = "create table KITH_AND_KIN (" 3 + "call text primary key, " 4 +"num text," 5 +"date integer)"; 6 7 public LastTimeDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { 8 super(context,name,factory,version); 9 10 } 11 12 @Override 13 public void onCreate(SQLiteDatabase sqLiteDatabase) { 14 sqLiteDatabase.execSQL(CREATE_KITH_AND_KIN); 15 } 16 17 @Override 18 public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { 19 20 } 21 }
增删改查:
public class KithAndKinService { private String call; private String num; private long date; private LastTimeDatabaseHelper dbHelper; public KithAndKinService(String call,String num,long date,LastTimeDatabaseHelper dbHelper) { this.call=call; this.num=num; this.date=date; this.dbHelper=dbHelper; } public KithAndKinService(String call, String num, LastTimeDatabaseHelper dbHelper) { this.call=call; this.num=num; this.dbHelper=dbHelper; } public KithAndKinService(String call,LastTimeDatabaseHelper dbHelper) { this.call=call; this.dbHelper=dbHelper; } public KithAndKinService(String call,long date,LastTimeDatabaseHelper dbHelper){ this.call=call; this.date=date; this.dbHelper=dbHelper; } public void insertToDatabase(){ SQLiteDatabase db = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("call",call); values.put("num",num); if(date!=0) { values.put("date",date); } db.insert("KITH_AND_KIN",null,values); } public void deleteInDatabase(){ SQLiteDatabase db = dbHelper.getWritableDatabase(); db.delete("KITH_AND_KIN","call=?",new String[] {call}); } public List<Map<String,String>> seleteInDatabase(){ SQLiteDatabase db = dbHelper.getWritableDatabase(); String temp = "call=?"; String[] temp2 ={call}; Cursor cursor = db.query("KITH_AND_KIN",null,temp,temp2,null,null,null); List<Map<String,String>> list= new ArrayList<Map<String,String>>(); if (cursor != null && cursor.moveToFirst()) { do { Map<String,String> map = new HashMap<String,String>(); map.put("call",cursor.getString(cursor.getColumnIndex("call"))); map.put("num",cursor.getString(cursor.getColumnIndex("num"))); map.put("date",cursor.getString(cursor.getColumnIndex("date"))); list.add(map); } while (cursor.moveToNext()); } return list; } public void updateToDatabase(){ SQLiteDatabase db = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("date",date); db.update("KITH_AND_KIN",values,"call=?",new String[] {call}); } }
然后是读取用户的通话记录
首先要权限
<uses-permission android:name="android.permission.READ_CALL_LOG" />
然后就是读取通话记录了:
1 public class CallInfoService { 2 private List<CallInfo> callInfos = new ArrayList<CallInfo>(); 3 4 public List<CallInfo> getCallInfos() { 5 ContentResolver resolver = MyApplication.getContext().getContentResolver(); 6 Uri uri = CallLog.Calls.CONTENT_URI; 7 String[] projection = new String[]{ 8 CallLog.Calls.NUMBER, 9 CallLog.Calls.DATE, 10 CallLog.Calls.TYPE 11 }; 12 if (ActivityCompat.checkSelfPermission(MyApplication.getContext(), Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) { 13 List<CallInfo> temp =new ArrayList<CallInfo>(); 14 temp.add(new CallInfo("0",0,0)); 15 return temp; 16 } 17 Cursor cursor = resolver.query(uri, projection, null, null, null); 18 while (cursor.moveToNext()){ 19 String number = cursor.getString(0); 20 long date = cursor.getLong(1); 21 int type = cursor.getInt(2); 22 callInfos.add(new CallInfo(number, date, type)); 23 } 24 cursor.close(); 25 return callInfos ; 26 27 } 28 }
数据处理:
玩下软工项目第一轮--全局Context的获取,SQLite的建立与增删改查,读取用户通话记录信息(随笔没写完)
标签:tap color 软件 api ring sel 一个 .exe move
原文地址:http://www.cnblogs.com/wkmocr/p/7676444.html