2

i am making an app that will allow specific number to ring while phone is silent and i successfully able to change phone state when a specific number cal. Now i need to access contact details, save them and let app access that when that number is calling so that i app can change its sound state. Please help me about resources ideas what things to do etc. I am also giving code of my app.......

public class MainActivity extends BroadcastReceiver {

    Context pcontext;
    @Override
    public void onReceive(Context context, Intent intent) {

        TelephonyManager tmngr= (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        pcontext=context;
        MyPhoneStateListener PhoneListener = new MyPhoneStateListener(pcontext);
        tmngr.listen(PhoneListener,PhoneStateListener.LISTEN_CALL_STATE);
    }

    private class MyPhoneStateListener extends PhoneStateListener {


        public MyPhoneStateListener(Context pcontext) {
           // pcontext=context;
        }

        public void onCallStateChanged(int state,String incoming)
        {
            AudioManager am=(AudioManager)pcontext.getSystemService(Context.AUDIO_SERVICE);
            String mode = "";
            if (state == 1) {

                String msg = "New Phone Call Event. Incomming Number : "+incoming;
                int duration = Toast.LENGTH_SHORT;
               // Context pcontext;

                if(incoming.equals("9588840")||incoming.equals("+9195648840"))
                {
                    Toast toast;
                    toast = Toast.makeText(pcontext, msg, duration);
                    toast.show();
                    am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                    if(am.getRingerMode()==(AudioManager.RINGER_MODE_NORMAL))
                    { mode="NORMAL_MODE";}
                    Toast.makeText(pcontext,mode,Toast.LENGTH_SHORT).show();
                }
                else
                {
                    if(am.getRingerMode()==(AudioManager.RINGER_MODE_NORMAL))
                    { mode="SILENT_MODE";}
                    am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                    Toast.makeText(pcontext,mode,Toast.LENGTH_SHORT).show();
                }
        }
    }
}
}
gauravmehra
  • 149
  • 2
  • 11

2 Answers2

0

You should start with Contacts in general. Then you can make changes. Here is some example.

Community
  • 1
  • 1
Alex
  • 4,457
  • 2
  • 20
  • 59
0

Well after some days of research i made that app.for its development i used sqlite for saving database for this i will refer http://www.tutorialspoint.com/android/android_sqlite_database.htm After that i made a dynamic broadcast receiver which will used when call state is ringing for dynamic broadcast receiver i used http://androidexample.com/Incomming_Phone_Call_Broadcast_Receiver__-_Android_Example/index.php?view=article_discription&aid=61&aaid=86 And after fetching data from contacts and comparing incoming number to each entry using cursors i was able to make the app. Thanks for stack member and teamsfor helping

gauravmehra
  • 149
  • 2
  • 11