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

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>

Related

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.

android Broadcastreceiver issue

Im developing an application,which blocks all outgoing calls and then after blocking that call ,another new call is initiated to a predefined number...
My problem is that,when i block the call using a broadcastreceiver,the second call which i programmatically initiate is also getting blocked...
Is any method to unregister the broadcast after blocking the first call,or any other method or technique???
This is my broadcastreceiver which i implemented for my app...
public class CallListenerActivity extends BroadcastReceiver {
Uri uri;
#Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(bundle == null)
return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.i("###OutgoingCallReceiver",phonenumber);
Log.i("###OutgoingCallReceiver",bundle.toString());
String info = "Detect Calls sample application\nOutgoing number: " + phonenumber;
Toast.makeText(context, info, Toast.LENGTH_LONG).show();
String phoneNumber = "5556";
Uri uri = Uri.fromParts("tel", phoneNumber, null);
Intent callIntent = new Intent(Intent.ACTION_CALL, uri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
}
You could try starting your original (CallListenerActivity? The one which registered the broadcast receiver) activity again using a flag stored as extra in the intent.
Evaluate the intent in your activity and unregister the broadcast receiver if you see the flag in the extras. Then start the the call activity as shown in your example code.
You can use store a check when you are initiating a call and after the completion of the call mark it. For this this check you can use SharedPreference.

register and unregister broadcast

I am to create an application.Through my application users can read the incoming phone number.My activity have two buttons, On and off. If the user clicks the on button ,then the following code will execute.
IntentFilter filter=new IntentFilter(TelephonyManager.EXTRA_STATE);
registerReceiver(new MyPhoneReceiver(), filter);
And If the user clicks the off button ,then the following code will execute.
unregisterReceiver(new MyPhoneReceiver());
MyPhoneReceiver is my brcastreceiver calss name.If the user is click the on button then the onReceive() method will be ready to read incoming call number and display that number.Likewise if I click the off button, then broadcast will be unregistered.
My onRecieve() code is
public void onReceive(Context context, Intent intent) {
System.out.println("am hereeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
Bundle extras = intent.getExtras();
if (extras != null) {
String state = extras.getString(TelephonyManager.EXTRA_STATE);
Log.w("sarath DEBUG", state);
System.out.println("state is:"+state);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.w("sarath DEBUG", phoneNumber);
System.out.println("phone no. is:"+phoneNumber);
}
}
}
My problem is when i click the on button nothing is happening.when a incoming call came then also its not executing onRecive() code.please help me friends
See this article:
Using PhoneStateListener to listen to state change in Android
Source code is here.
This method requires the permission in AndroidManifest.xml. You added any permissions in your application?

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