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.