Stopping & starting music on incoming calls

There are a few things you can do: First of all, you can listen for changes in the call state using a PhoneStateListener. You can register the listener in the TelephonyManager: PhoneStateListener phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { if (state == TelephonyManager.CALL_STATE_RINGING) { //Incoming call: Pause music } … Read more

How can incoming calls be answered programmatically in Android 5.0 (Lollipop)?

Update with Android 8.0 Oreo Even though the question was originally asked for Android L support, people still seem to be hitting this question and answer, so it is worth describing the improvements introduced in Android 8.0 Oreo. The backward compatible methods are still described below. What changed? Starting with Android 8.0 Oreo, the PHONE … Read more

How to block calls in android

OMG!!! YES, WE CAN DO THAT!!! I was going to kill myself after severe 24 hours of investigating and discovering… But I’ve found “fresh” solution! // “cheat” with Java reflection to gain access to TelephonyManager’s // ITelephony getter Class c = Class.forName(tm.getClass().getName()); Method m = c.getDeclaredMethod(“getITelephony”); m.setAccessible(true); telephonyService = (ITelephony)m.invoke(tm); all all all of hundreds … Read more

How to detect incoming calls, in an Android device?

Here’s what I use to do this: Manifest: <uses-permission android:name=”android.permission.READ_PHONE_STATE” /> <uses-permission android:name=”android.permission.PROCESS_OUTGOING_CALLS”/> <!–This part is inside the application–> <receiver android:name=”.CallReceiver” > <intent-filter> <action android:name=”android.intent.action.PHONE_STATE” /> </intent-filter> <intent-filter> <action android:name=”android.intent.action.NEW_OUTGOING_CALL” /> </intent-filter> </receiver> My base reusable call detector package com.gabesechan.android.reusable.receivers; import java.util.Date; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.telephony.TelephonyManager; public abstract class PhonecallReceiver extends … Read more