android - How to allow the particular calls to ring and others to be silent? -
I want to make an Android app based on incoming calls.
While calling important people I should get an incoming call, but if others call my phone then be silent.
Since I am new to Android, this is very difficult for me.
There may be four steps to achieve your requirement.
- Get an incoming number
- Compare it with your data (which can be stored in the database or in shared priority)
- Ring silent
Receive incoming number:
call you a broadcast receiver
call
& lt; Receiver Android: name = ". CallReceiver" & gt; & Lt; Intent-Filter & gt; & Lt; Action Android: name = "android.intent.action.PHONE_STATE" /> & Lt; / Intent-Filter & gt; & Lt; / Receiver & gt; In that broadcast you need to add
with the phone parameter onPhoneStateListener
to your telephony manager, overriding the callstate switch (). this is.
CallReceiver.Java
Public Class CallReceiver Broadcast Expands Extend {@ Override Public Nil Receive (Last Reference Reference, Intent Intention) {telephony manager telephony = (telephony manager) context.getSystemService (context.TELEPHONY_SERVICE); Telephony.listen (New Phonestate Lastner) {@Override CallState Changel (Ent State, String Number) at Public Zero {super.onCallStateChanged (state, number); System.out.println ("number:" + number); // Compare your number If you are found in this list, Ring State manga audio manager = (Audio Manager) To create YourActivityName.this, if you are found in the list then ring state RINGER_MODE_NORMAL // and make it RINGER_MODE_SILENT Give (number found in the list) Ring Stay System system (context. AUUDIO_SERVICE); audiomanager.setRingerMode (AudioManager.RINGER_MODE_SILENT);} Other {// ringable} Audio Manager Audience = (Audio Manager) YourActivityName.this.getSystemService (Context.AUDIO_SERVICE); Audiomanager.setRingerMode (AudioManage r.RINGER_MODE_NORMAL);}}}, the phone's listener. LISTEN_CALL_STATE;}
Ring the ring:
< Code> Audio Manager AudioGenre = (Audio Manager) YourActivityName.this.getSystemService (Context.AUDIO_SERVICE); Audiomanager.setRingerMode (AudioManager.RINGER_MODE_SILENT);
Comments
Post a Comment