BroadcastReceiver for call answers - android

I'm trying to programmatically intercept a call answer.
I've got a BroadcastReceiver with the following method:
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
String state = extras.getString(TelephonyManager.EXTRA_STATE);
if(state.equals("OFFHOOK")) {
// ...
}
// ANSWER ??
}
}
While the code works successfully if the phone receives a call (offhook is related to the answer, because before I've got the ringing state) I can't detect the answer relatively to a placed call: in this case offhook is relative to the ringing.
How can I intercept the answer relatively to a placed call?

Related

onReceive called even when Broadcast not sent [duplicate]

I have a registered BroadcastReceiver in my main activity. Activity sends a sticky in one of the tabs to trigger the broadcast receiver (TabActivity application).
Everything works fine, but when I restart the app the sticky is sent automatically (not triggered by user) and view is opened.
My question is: how is that possible? Did I misunderstand something? And how can I fix that?
MainActivity:
OnCreate:
registerReceiver(openOutgoingCall, new IntentFilter("OPENOUTGOINGCALL"));
BroadcastReceiver:
private BroadcastReceiver openOutgoingCall = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if(extras.isEmpty() == false) {
HashMap<String,String> callData = (HashMap<String, String>) extras.get("callData");
openOutgoingCall(callData);
}
}
};
Activity inside TabHost
public void openCall(View view) {
Intent i = new Intent("OPENOUTGOINGCALL");
i.putExtra("callData", detailInfo);
sendStickyBroadcast(i);
}
Sticky broadcasts are supposed to stay around (even they are received) so that they can be retrieved afterwards too. Perhaps you should try the simple way of broadcasting using:
sendBroadcast(i);
Read this.

Broadcast receiver is triggered automatically on start

I have a registered BroadcastReceiver in my main activity. Activity sends a sticky in one of the tabs to trigger the broadcast receiver (TabActivity application).
Everything works fine, but when I restart the app the sticky is sent automatically (not triggered by user) and view is opened.
My question is: how is that possible? Did I misunderstand something? And how can I fix that?
MainActivity:
OnCreate:
registerReceiver(openOutgoingCall, new IntentFilter("OPENOUTGOINGCALL"));
BroadcastReceiver:
private BroadcastReceiver openOutgoingCall = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if(extras.isEmpty() == false) {
HashMap<String,String> callData = (HashMap<String, String>) extras.get("callData");
openOutgoingCall(callData);
}
}
};
Activity inside TabHost
public void openCall(View view) {
Intent i = new Intent("OPENOUTGOINGCALL");
i.putExtra("callData", detailInfo);
sendStickyBroadcast(i);
}
Sticky broadcasts are supposed to stay around (even they are received) so that they can be retrieved afterwards too. Perhaps you should try the simple way of broadcasting using:
sendBroadcast(i);
Read this.

How to filter incomming calls (blacklist) - no reflection

I was wondering if there is a way that I can filter (block) incoming calls on Android (consider 2.1 and up). I found solutions using reflection, but it seem not to be very clean and reliable solution. Is there any standard or google recommended way to do that?
UPDATE: Anyone?
use the following broadcast receiver to get the incoming phone number and compare it with the numbers that are in your created filter list
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
String state = extras.getString(TelephonyManager.EXTRA_STATE);
Log.w("DEBUG", state);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = extras
.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast.makeText(context, phoneNumber, 2000).show();
Log.w("DEBUG", phoneNumber);
}
}
}
Hope it will help. You need to create a list of numbers in blacklist by your application's User interface.

How can I hide/cancel the default incoming screen

I am currently intercepting a call and forwarding it to my customized "oncallscreen" activity. However, before getting to my screen it will flash to the default "oncallscreen". How can I hide/cancel this screen so when receiving call I get only my customized screen.
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
String state = extras.getString(TelephonyManager.EXTRA_STATE);
Log.w("DEBUG", state);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = extras
.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
You need to intercept broadcast android.intent.action.PHONE_STATE with highest possible priority, then if in your BroadcastReceiver.onReceive() you will cancel broadcast through BroadcastReceiver.abortBroadcast() you will be able to stop default incoming call screen to be shown, since default application won't receive incoming call broadcast. After that you're free to show your own Activity.

How to track android phone call after dial the call button and before ringing in Android application

I want to track the phone call information after dialing the call button and before ringing.Means before going call to the person whom I want to call, I want to a notification in my application.
public class CallReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// Try to read the phone number from previous receivers.
String phoneNumber = getResultData();
if (phoneNumber == null) {
// We could not find any previous data. Use the original phone number in this case.
phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
}
}
}
You can retrieve this from a Broadcast in response to ACTION_NEW_OUTGOING_CALL:
Register a BroadcastReceiver with an ACTION_NEW_OUTGOING_CALL intent filter. You can also read this Android Developers blog post regarding some details on the subject.

Categories

Resources