1. Are you ready for the Galaxy S20? Here is everything we know so far!

can anyone help on programming phone

Discussion in 'Android Development' started by tweacle, Aug 14, 2013.

  1. tweacle

    tweacle Newbie
    Thread Starter

    Hi there

    Ive been told to do this on my phone:

    First of all, you can listen for changes in the call state using a PhoneStateListener. You can register the listener in the TelephonyManager:


    How do I get into it?

    Thanks
     



    1. Download the Forums for Android™ app!


      Download

       
  2. electricpete

    electricpete Android Expert

    It's not clear what your asking.

    To what app does your question pertain?

    Thinking about programming your own app in something like
    ... Java? If so, I don't think this is the right forum
     
  3. ocnbrze

    ocnbrze DON'T PANIC!!!!!!!!!

    moved to the android development forum
     
  4. out of ideas

    out of ideas Android Enthusiast

    Yeah thats java code stuff. not something you can just access from your phone.
     
  5. steve

    steve Developer
    Administrator

    Yes, you can. Lots of apps out there use this TelephonyManager class. You will need to be able to build a basic android application along with basic Java knowledge.

    Here is an example of how you could use this class:

    First in your manifest you will need this permission:
    [HIGH]
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />[/HIGH]

    and a receiver like this:
    [HIGH]
    <receiver android:name=".PhoneServiceReceiver">
    <intent-filter>
    <action android:name="android.intent.action.PHONE_STATE" />
    </intent-filter>
    </receiver>
    [/HIGH]

    Then you will need to classes (or one depending how you want to set everything up)


    ServiceReceiver
    [HIGH]
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.telephony.PhoneStateListener;
    import android.telephony.TelephonyManager;

    public class ServiceReceiver extends BroadcastReceiver {

    TelephonyManager telephony;

    public void onReceive(android.content.Context context, Intent intent) {
    CustomStateListener phoneListener = new CustomStateListener();
    telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
    }

    public void onDestroy() {
    telephony.listen(null, PhoneStateListener.LISTEN_NONE);
    }

    }
    [/HIGH]

    and

    CustomStateListener
    [HIGH]
    import android.telephony.PhoneStateListener;
    import android.telephony.TelephonyManager;
    import android.util.Log;

    public class CustomStateListener extends PhoneStateListener {

    public static Boolean isRinging = false;

    public void onCallStateChanged(int state, String incomingNumber) {

    switch (state)
    {
    case TelephonyManager.CALL_STATE_IDLE:
    Log.d("TEST", "Phone - IDLE");
    isRinging = false;
    break;

    case TelephonyManager.CALL_STATE_OFFHOOK:
    Log.d("TEST", "Phone - OFFHOOK");
    isRinging = false;
    break;

    case TelephonyManager.CALL_STATE_RINGING:
    Log.d("TEST", "Phone - RINGING");
    isRinging = true;
    break;

    }
    }

    }
    [/HIGH]

    Hope this helps you.. or someone.
     
    ocnbrze likes this.
Loading...
Similar Threads - anyone help programming
  1. JonEknoxpoke
    Replies:
    1
    Views:
    617
  2. DonB
    Replies:
    1
    Views:
    654
  3. JGWM
    Replies:
    8
    Views:
    1,300
  4. Milo Williamson
    Replies:
    5
    Views:
    629
  5. Tieje
    Replies:
    1
    Views:
    541
  6. curiouscat22
    Replies:
    1
    Views:
    686
  7. catchingup
    Replies:
    1
    Views:
    534
  8. Gobshyte
    Replies:
    5
    Views:
    2,699
  9. MrKrab
    Replies:
    13
    Views:
    978
  10. ChrisGalaxys9
    Replies:
    3
    Views:
    1,039

Share This Page

Loading...