I have an app that has to perform certain actions after phone call is ended.
like in my application after every call i should save the call time, duration and write it to text file for further processing. Main problem here is how do I know that call is just ended.
I have checked Telephony manager like
TelephonyManager.CALL_STATE_RINGING
TelephonyManager.CALL_STATE_OFFHOOK
But I am still unable to achieve this task. Any help please.
Check out BroadcastReceiver. And here is a nice tutorial on how to catch changes in the phone state.
Related
I am working on an App that should detect when Phone Call is placed on hold, all I can find in Android Telephony documentation is 3 states, that is CALL_STATE_RINGING when Phone is ringing, CALL_STATE_OFFHOOK When call is in progress or on Hold or CALL_STATE_IDLE when no call activity exists, but I would like to know, has anyone found out a way around to detect exactly when call is on Hold? I need to do some action only when call is on hold.
Take a look at this answer https://stackoverflow.com/a/29490832/3836513 . Using PreciseCallState you can read when call is put on hold.
This is possible in Android 5.0 using the The PreciseCallState, You can read call state such as idle,busy and ringing.GithubCode PreciseCallStateDetail
I have developed Twilio SDK in my Android application. For outgoing and incoming it is worked well. But when i try to set the timer for call duration, i am unable to get the notification from the other device. Is there any method to find out the other device(Which was notified after picking the call)?
Please help me on this.
Thanks,
I'm not sure if you still need help with this or not, or I get exactly your issue.
What I'm doing is keeping the timestamp of when the call was started (incoming/outgoing) in any of the clients. Then in my activity/fragment, since I have my own callbacks for the Twilio events, as soon as I know there's a call going on, I use Chronometer which is like a TextView that automatically sets things as soon as you set a base time and start it.
get timestamp of when that call started
Chronometer.setBase(timestamp);
Chonometer.start();
So it shows the duration. Remember to have your own Twilio manager class to hold that value for you so if you leave your activity and come back, the duration will be displayed correctly.
Good luck
I am new to android development and I did research on notifications using toast and status bar notification.
And I also managed to execute the code properly to make a notification work!!!
The problem is there are only methods like triggering a notification by clicking a button is available. Other wise I managed to directly call the codes within the method that is called by the button, to make it trigger automatically. But the problem is the view of the corresponding screen is showing up a tleast for a sec and then closing while this notification is triggered.
So how can i write a code that just triggers the notification without popping up the screen even for a second.
I need a result like the way the new SMS alert works...And I did a lot of research on this and all I got was about basic notification. So please help as I am new to this!!!
Using a Service would be the "right" way to do it - and if this is a professional app you are writing, then that's the way to go.
Bear in mind you still need some activities in your application, in order to trigger the service.
If you are just experimenting, then maybe what you need is a cheap hack...
Here's the cheap and nasty way to get your proof-of-concept done:
either - create a transparent Activity so that nothing is displayed when the activity code gets called.
or - create your notification from within the Activity.onCreate() method, and then call finish() at the end of that method. Your activity will never get shown to the user.
To me, it looks like you are just experimenting, and a transparent activity might get you further faster... ymmv
Legendary you need service and handler. Using service you can get data. and using handler you can modify the UI of your app.
here you can get more information on it.
http://developer.android.com/training/notify-user/display-progress.html
Working with handlers and threads in service, Thread.sleep makes the program to hang?
I want to specifically know who ended the call. I have setup a broadcast receiver for
"android.intent.action.PHONE_STATE"
When I detect a transition from Off hook to idle, I know the call has ended. But how do I know who ended the call?
Thanks a ton!
I'm afraid there's presently no way to determine if the user pressed "end call" or if the other end (or ends, in a group call) terminated. The only workaround I can suggest is monitoring the other states to observe if the phone state ringing was encountered. In such a case, you could assume the user is making the phone call as opposed to receiving it.
Bear in mind that there are other problems related to PHONE_STATE, such as handling multiple calls simultaneously.
In retrospect, I'm not entirely sure what you mean with "who". As for other apps ending the call: there is no official API to end phone calls; only through reflection can an app invoke the TelephonyService's endCall() function. Here, too, it is not possible to determine if the call was terminated through user interaction or not.
I'm developing an application for android 2.3.3. It contains a few EditView's to show an information for an incoming call: country, current time, phone number... I know how to get and show that information. The problem I faced is that I don't know how to show my activity instead of the standard screen for incoming calls.
Now it shows the information after the incoming calls.
How to do it?
It's not possible. According to the PhoneApp the intent used to start the InCallScreen is bound to the phoneapp, you have no chance to intercept this. So the screen will be shown every time.
What you may try to do is to be notified by the TelephonyManager when the phone goes into the CALL_STATE_RINGING state and then paint your UI just over the InCallScreen. It may be possible to do so but you woudn't be able to offhook the call (unsure, but I don't think so) from your UI. Also the state is not set immediately when the InCallScreen pops up, it's delayed by some milliseconds.
Take a look at the questions about showing popups over the incoming call screen:
Popup over incoming-call screen
android incoming call screen
If it isn't enough to show a popup over the incoming call UI, then you could make your popup cover the whole screen to hide it. At that point you'll need a way to accept the incoming call without showing the default incoming call screen (which you are now covering). A quick search found this answer that suggests a workaround to accept the incoming call. I'm not sure offhand if there is an official API to do it.
It's impossible to remove the default UI of the incoming call in android, unless you modify the Android OS codings. But instead you can use your own custom UI activity over the default one. It's attained by using the Thread concept(to make the custom designed UI come-over the default one)!!