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

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.

Related

Receive message SmartEyeglass ControlExtension

I want to make an app for Sony SmartEyeglass where the App on the Phone and the ControlExtension exchange data on runtime.
It's pretty obvious how to send messages from the app to the extension...
public void startExtension(String msg) {
if (HelloWorldExtensionService.Object != null) {
HelloWorldExtensionService.Object
.sendMessageToExtension(msg);
}
}
but how do I get the msg in my ControlExtension, if the extension is already running?
I didn't find an onMessageReceived(String message) method for the class ControlExtension.
You can do this using Intents the same way you would for an standard Android app. For example from your Activity:
Intent intentBuzz = new Intent();
intentBuzz.setAction(buzzIntent);
mContext.sendBroadcast(intentBuzz);
Then in your Control Extension register a broadcast receiver:
buzzReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
buzzAction();
}
};
registerReceiver(buzzReceiver, new IntentFilter(buzzIntent));
This works the other way around as well if you want to pass something other than a string.

Android Check if call forwarding is activated

I am building a call forwarding application and have used the **21*xxxxxx# ussd code to activate call fowarding using ACTION_CALL Intent. But I have not found a solution to check whether Call forwarding is active or not.
Is there any solution to check from the android system if call forwarding is active or not?
TelephonyManager manager = (TelephonyManager)
this.getSystemService(TELEPHONY_SERVICE);
manager.listen(new MyPhoneStateListener(),
PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR );
class MyPhoneStateListener extends PhoneStateListener{
#Override
public void onCallForwardingIndicatorChanged(boolean cfi) {
Log.i(TAG,"onCallForwardingIndicatorChanged CFI ="+cfi);
preferences.edit().putBoolean("CALL_FORWARD_ACTIVE", cfi).commit();
super.onCallForwardingIndicatorChanged(cfi);
}
}
if cfi returns true that means set call forward success
you can make Brodcast class register it and you can track out going call like
public class CallBroadcastReceiver extends BroadcastReceiver
{
public static String numberToCall;
public void onReceive(Context context, Intent intent) {
Log.d("CallRecorder", "CallBroadcastReceiver::onReceive got Intent: " + intent.toString());
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
numberToCall = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.d("CallRecorder", "CallBroadcastReceiver intent has EXTRA_PHONE_NUMBER: " + numberToCall);
}
}
}
PRECAUTION:
The following answer is suggestion. I haven't tried it personally So you better try it to check the result.
From your gsm number you can check your call forwarding options by dialing *#21#. So you can try dialing this number from application and read the ussd response.
part 1: to dial the number
Intent intentCallForward = new Intent(Intent.ACTION_CALL);
Uri uri = Uri.fromParts("tel", "*#21#", "#");
intentCallForward.setData(uri);
startActivity(intentCallForward);
part 2: to read the ussd response
There is no API to do this. But here in this SO answer it suggested some methods that you can try.
Best of luck
yes you can use *#21# to check for CF in the same way as you used **21*xxxxxx# to activate CF.
BTW, these are MMI code, not USSD code.

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>

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?

Small confusion about PhoneStateIntentReceiver

public class MyReceiver extends PhoneStateIntentReceiver {
#Override
public void onReceiveIntent(Context context, Intent intent) {
if (intent.action == Intent.CALL_ACTION) {
}
}
}
Assume that notifyPhoneCallState has been called to enable MyReceiver to receive notifications about phone call states, in which case the code will get executed?
when device receives an incoming call
when outgoing call is initiated on the device
when the user presses the call button
incoming phone call is terminated
or will the code not be executed at all?
Did you mean public static final String ACTION_CALL instead of CALL_ACTION?
Activity Action: Perform a call to someone specified by the data.
Input: If nothing, an empty dialer is started; else getData() is URI of a phone number to be dialed or a tel: URI of an explicit phone number.
Output: nothing.
Note: there will be restrictions on which applications can initiate a call; most applications should use the ACTION_DIAL.
Note: this Intent cannot be used to call emergency numbers. Applications can dial emergency numbers using ACTION_DIAL, however.

Categories

Resources