How to filter incomming calls (blacklist) - no reflection - android

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.

Related

BroadcastReceiver for call answers

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?

I want my android app to start when a phone receives a call and to get the incoming phone number

I want my android app to start when a phone receives a call and to get the incoming phone number, i what to be able to put button on the screen of the incoming call and before that to be able to get the number calling, it would be of much help i anyone can refer me to some examples or materials. thx
You can setup a broadcastlistener in your AndroidManifet.xml You must setup your intent to listen for android.intent.action.PHONE_STATE
Then you get the phone state from the intent with intent.getExtraString(TelephonyManager.EXTRA_STATE) . If it's OFFHOOK or RINGING then a call has come in and you can get the phone number from the intent with intent.getExtraString(TelephonyManager.EXTRA_INCOMING_NUMBER)
This will toast and log the incomming number...
public class CallReceiveD extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
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 toast= Toast.makeText(context,phoneNumber, Toast.LENGTH_LONG);toast.show();
Log.w("DEBUG", phoneNumber);
}
}
}
}
dont forget the manifest file
< receiver
android:name=".CallReceiveD">
< action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>

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.

C2DM - onMessage, interactivity with results I get

I am successfully getting messages from C2DM service. Unfortunately I am not able to anyhow interact with them (set the string I get as a notification, or set it as a string in toast message,...). Is there any example how to do that?
SC:
#Override
protected void onMessage(Context context, Intent intent) {
Log.e("C2DM", "Message: arived");
Bundle extras = intent.getExtras();
if (extras != null) {
Log.d("DATA_ZE_SERVERU",extras.get("payload")+"");
//how to interact with data?
}
}
Thx
Nobody knows???
You can pass the string to a activity and let the activity show it. I did most of my c2dm like that.

Categories

Resources