1.Setting.Secure
PS:Secure system settings, containing system preferences that applications can read but are not allowed to write. These are for preferences that the user must explicitly modify through the system UI or specialized APIs for those values, not modified directly by applications.
2.BroadcastReciver 广播接收者
3.context
http://blog.csdn.net/qinjuning/article/details/7310620
4.intent和intentFileter
http://liuzhichao.com/p/506.html
5. android 4.4以后短信拦截。
无法拦截cancle Broadcast。
6.获本机联系人的手机号并匹配
class ifNumAlreadyExist extends Thread{
String interceptPhonenumber;
ifNumAlreadyExist(String interceptPhonenumber){
this.interceptPhonenumber = interceptPhonenumber;
}
public void run(){
ifNumExist =ifNumAlreadyExisting(interceptPhonenumber);
}
private boolean ifNumAlreadyExisting(String interceptPhonenumber) {
Cursor cur = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
//循环遍历
if (cur.moveToFirst()) {
int idColumn = cur.getColumnIndex(ContactsContract.Contacts._ID);
int displayNameColumn = cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
do {
//获得联系人的ID号
String contactId = cur.getString(idColumn);
//获得联系人姓名
String disPlayName = cur.getString(displayNameColumn);
//查看该联系人有多少个电话号码。如果没有这返回值为0
int phoneCount = cur.getInt(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if(phoneCount>0){
//获得联系人的电话号码
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID+ " = " + contactId, null, null);
if(phones.moveToFirst()){
do{
//遍历所有的电话号码
String phoneNumber= phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
if(interceptPhonenumber.equals(phoneNumber)){
return true;
}
}while(phones.moveToNext());
}
}
} while (cur.moveToNext());
}
return false;
}
}
7.handler和多线程
首先在Activity中创建一个继承自Handler的匿名内部类以及这个类的一个对象
Private MainHandler mMainHandler = new MainHandler();
private class MainHandler extends Handler {
public voidhandleMessage(android.os.Message msg) {
switch (msg.what) {
case MSG_MAIN_HANDLER_TEST:
Log.d(TAG, "MainHandler-->handleMessage-->thread id =" + Thread.currentThread().getId());
break;
}
}
};
这样在Activity的其他地方就可以通过mMainHandler对象发送消息给Handler处理了
Message msg = mMainHandler.obtainMessage(MSG_MAIN_HANDLER_TEST);
mMainHandler.sendMessage(msg);