Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

Android say caller name

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...