• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps can anyone help on programming phone

tweacle

Newbie
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
 
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
 
can listen for changes in the call state using a PhoneStateListener. You can register the listener in the TelephonyManager

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.
 
Back
Top Bottom