public class MyPhoneStateListener extends PhoneStateListener { private String[] projection = new String[] { People._ID, People.NAME, People.NUMBER }; public void onCallStateChanged(int state,String incomingNumber){ switch(state) { case TelephonyManager.CALL_STATE_IDLE: Log.d("DEBUG", "IDLE"); break; case TelephonyManager.CALL_STATE_OFFHOOK: if(!incomingNumber.equals("")){ handleCall(incomingCall); } break; case TelephonyManager.CALL_STATE_RINGING: Log.d("DEBUG", "RINGING"); break; } } public void handleCall(String incomingCall){ Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, incomingNumber); contactsCursor = context.getContentResolver().query(contactUri, projection, null , null, People.NAME + " ASC"); if(contactsCursor.moveToFirst()){ int phoneNameIndex = contactsCursor.getColumnIndex(People.NAME); String phoneNameStr = contactsCursor.getString(phoneNameIndex); Log.d("DEBUG",phoneNameStr + " is calling"); }else{ Log.d("DEBUG","Not a contact"); } } }
Quick Explanation
Looking on the handleCall function, there is nothing really new here, for the BroadcastReceiver explanation go to this page and for the displaying contact names go to this page. Sorry i'm too lazy to explain here coz i already explained it on the previous post.
Anyway i have to temporarily stop my android adventure and do some stuff for work which is webbased stuff so the next article would be web based article. Thanks
Update History
Jan 17, 2012 - Visual Update
1 comment:
When you use the read_phone_state permission, where is the information stored? Say for example, you need the unique device ID, where does it go so you can retrieve it?
Post a Comment