Retrieve phone number from call log android
I want to retrieve the number available in the call log in android application.
I do not want to get all the call log and populate in my app activity. Instead I want to use existing android In开发者_如何转开发tent to view and once selected the number from the list, I want the number back in my activity.
I guess I will have to use startActivityForResult for this. But what I am confused is what will be the code in this method. I want only the number.
Any help will be appreciated.
Regards, Shankar
ok, first from activity A you should create intent
Intent i=new Intent(...);
startActivityForResult(i,0)
and on the activity B you do this
Intent i1=getIntent();
//here you put data
i.putExtra("key","value");
and than in the first activity, activity A you get your data like this in the method:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
String dataINeeded=data.getExtra("key");
}
that's it
String[] strFields = {
android.provider.CallLog.Calls.NUMBER,
android.provider.CallLog.Calls.TYPE,
android.provider.CallLog.Calls.CACHED_NAME,
android.provider.CallLog.Calls.CACHED_NUMBER_TYPE
};
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
Cursor mCallCursor = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI,
strFields,
null,
null,
strOrder
);
if(mCallCursor.moveToFirst()){
// loop through cursor
do{
int ind=mCallCursor.getColumnIndex(android.provider.CallLog.Calls.NUMBER);
int ind1=mCallCursor.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME);
Log.v("asd", "NUmber:"+mCallCursor.getString(ind)+" Name:"+mCallCursor.getString(ind1));
} while (mCallCursor.moveToNext());
}
You can get any info you need , this is just the way to do it
精彩评论