-1

How can I say caller name on receiving call. https://groups.google.com/forum/#!topic/tasker/V_z1YJ6lBGQ http://www.tutorialspoint.com/android/android_text_to_speech.htm There is something mentioned but i have done that, i have received caller name, now I want to convert that text to speech in on received method. I did used event handler and i send that name to other activity but it didn't say name when app is closed.

user2409402
  • 181
  • 1
  • 8

2 Answers2

0
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

Auto-Droid ツ
  • 1,583
  • 1
  • 17
  • 31
0

First Detect Contact number whenever any new call arrives,This thread will help you to do so

Retrieve incoming call's phone number in Android

And once you have detect the contact number of incoming call, than you can compare that contact number with the list of all contact saved on your device.

Use below method for getting all contact names and numbers from your device

ContentResolver cr = getContentResolver();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
                null, null, null, null);
        if (cur.getCount() > 0) {
            while (cur.moveToNext()) {
                  String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                  String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                  if (Integer.parseInt(cur.getString(
                        cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                     Cursor pCur = cr.query(
                               ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                               null,
                               ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
                               new String[]{id}, null);
                     while (pCur.moveToNext()) {
                         String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                         Toast.makeText(NativeContentProvider.this, "Name: " + name + ", Phone No: " + phoneNo, Toast.LENGTH_SHORT).show();
                     }
                    pCur.close();
                }
            }
        }

For more detail about this you can check this guideline

http://saigeethamn.blogspot.in/2011/05/contacts-api-20-and-above-android.html

Community
  • 1
  • 1
Aamirkhan
  • 5,746
  • 10
  • 47
  • 74