Android Custom Caller Interface implementation

Source: Internet
Author: User

Scenario Requirements

When the phone calls, sometimes not easy to answer the phone, hoping to touch the screen to achieve the effect of silence, and then answer the phone.

Development ideas

First you have to get a phone call event, and then listen to the screen click events, so that the phone ringtone mute

Difficult point

Mobile phone Call event, is the highest priority in the system, third-party applications can not change the system comes with the call function.

Solutions

Looking at some of the common practices on the Internet, downloaded some applications of caller ID, by observing that the current practice is generally:

First backstage always have a service, listen to the incoming call event, when the call, jump to the third-party application interface, on this interface to make calls

Page optimization, such as can answer, hang up the phone, the interface to do more than the system comes with more beautiful ... In fact, this time the system comes with the incoming call also in

Running in the background, just if the phone is answered or hung up in our application, the event in the system is turned off.

Related code
1     Public voidOnReceive (Context context, Intent Intent) {2         FinalContext CTX =context;3         FinalShowpref pref =showpref.getinstance (CTX);4         /**5 * How to display the interface6          */7         Final intShowType =Pref.loadint (showpref.show_type);8 9Telmgr =(Telephonymanager) Ctx.getsystemservice (service.telephony_service);Ten         Switch(Telmgr.getcallstate ()) { One              CaseTelephonymanager.call_state_ringing://Incoming call ringing ASystem.out.println ("............") Master, the guy's on the phone again .......... "); -                 FinalString number =Intent.getstringextra (telephonymanager.extra_incoming_number); -System.out.println ("Number:" +Number ); the  -                 if(number.length () = = 11) { -                     synchronized(monitor) { -                         Switch(showtype) { +                              Caseshowpref.type_activity: -                                 NewHandler (). postdelayed (NewRunnable () { + @Override A                                      Public voidrun () { at                                         //TODO auto-generated Method Stub - showactivity (CTX, number); -                                     } -}, 1000); -                                  Break; -                              CaseShowpref.type_full_dialog: in                                 NewHandler (). postdelayed (NewRunnable () { - @Override to                                      Public voidrun () { +                                         //TODO auto-generated Method Stub -ShowWindow (CTX, number, 100); the                                     } *}, 100); $                                  Break;Panax Notoginseng                              CaseShowpref.type_half_dialog://Non-Full Screen dialog -                             default://Display Half Screen dialog by default the                                 intValue =Pref.loadint (Showpref.type_half_value, + showpref.type_half_dialog_default); A                                 Final intPercent = value >= 25? (Value <= value:75): 25; the                                 NewHandler (). postdelayed (NewRunnable () { + @Override -                                      Public voidrun () { $                                         //TODO auto-generated Method Stub $ ShowWindow (CTX, number, percent); -                                     } -}, 100); the                                  Break; -                         }Wuyi                     } the                 } -                  Break; Wu              CaseTelephonymanager.call_state_offhook://answer the phone -                  Break; About              CaseTelephonymanager.call_state_idle://Hang up the phone $                 synchronized(monitor) { -                     Switch(showtype) { -                          Caseshowpref.type_activity: - Utils.sendendcallbroadcast (CTX); A                              Break; +                          CaseShowpref.type_full_dialog: the                          CaseShowpref.type_half_dialog: -                         default://A half-screen dialog is displayed by default $ CloseWindow (CTX); the                              Break; the                     } the                 } the                  Break; -             default: in                  Break; the         } the  About}
View Code

Listening permissions:

1<!--the right to hang up your phone--2<uses-permission android:name= "Android.permission.CALL_PHONE"/>3 4<!--permission to read the phone's status--5<uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>6<!--system-level popup permissions--7<uses-permission android:name= "Android.permission.SYSTEM_ALERT_WINDOW"/>8<!--unlock Permissions--9<uses-permission android:name= "Android.permission.DISABLE_KEYGUARD"/>Ten<!--permissions on the screen-- One<uses-permission android:name= "Android.permission.WAKE_LOCK"/> A<!--network operation permissions-- -<uses-permission android:name= "Android.permission.INTERNET"/> -<!--read network status-- the<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/> -  -<uses-permission android:name= "Android.permission.RESTART_PACKAGES"/> -      +<Application -android:icon= "@drawable/icon" +Android:label= "@string/app_name" > A<Activity atAndroid:name= "Com.likebamboo.phoneshow.MainActivity" -Android:label= "@string/app_name" > -<intent-filter> -<action android:name= "Android.intent.action.MAIN"/> -  -<category android:name= "Android.intent.category.LAUNCHER"/> in</intent-filter> -</activity> to<Activity +Android:name= "Com.likebamboo.phoneshow.OverLayActivity" -Android:label= "@string/app_name" > the</activity> *<!--register to monitor phone status-- $<receiver android:name= "Com.likebamboo.phoneshow.PhoneStateReceiver" >Panax Notoginseng<intent-filter android:priority= ">" -<action android:name= "Android.intent.action.PHONE_STATE"/> the</intent-filter> +</receiver> A  the<Service +Android:name= "Com.likebamboo.phoneshow.ScreenService" -Android:label= "@string/app_name" > $</service>
View Code

Project Source

Source code. zip

Android Custom Caller Interface implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.