1. 程式人生 > >android實習期日常筆記(三)

android實習期日常筆記(三)

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);