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.

  1. Get an incoming number
  2. Compare it with your data (which can be stored in the database or in shared priority)
  3. Ring silent

Receive incoming number:

call you a broadcast receiver call call receiver Need to assign its action to code> manifest.

  & 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  PhoneStateListener  to your telephony manager, overriding the callstate switch ()  with the phone parameter on . 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

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -