Bundle bundle = intent.getExtras();
if(null == bundle)
return;
String state = bundle.getString(TelephonyManager.EXTRA_STATE);
if(incoming_flag==true){
if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
{
////////testing ends
String phonenumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
// String personname=bundle.getString(TelephonyManager.)
Log.i("IncomingCallReceiver","Incomng Number: " + phonenumber);
ContentResolver con =null;
//testing name
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phonenumber));
Cursor cursor = context.getContentResolver().query(uri, new String[]{PhoneLookup.DISPLAY_NAME},null,null,null);
if (cursor.moveToFirst())
{
name = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME));
}
You will have to generate a broadcast for it to detect incoming call the use the intent of onRecieve param to get name the above sample code shows the way to do it, you will have to write a service which will start from broadcast to play caller name use text to speech method
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…