Android : Phone call detect when connected? - java

I can use this code to make outgoing call:
Intent dial = new Intent(Intent.ACTION_CALL);
dial.setData(Uri.parse("tel:5556") );
context.startActivity(dial);
But how to detect whether the call is picked up or the call is refused?
I tried PhoneStateListener, but it is not working.

Unfortunately, Android gives no mean to know when an outgoing call has been answered.
PhoneStateListener works fine but the 3 states notified by onCallStateChanged are not enough. An additional state like CALL_STATE_CONNECTED would be welcome.
There is an open issue requesting this feature but it didn't get much attention so far:
https://code.google.com/p/android/issues/detail?id=14266
Some people (like me) falls back using logcat and tries to infer if an outgoing call has been answered but this is far from an ideal solution.

I am also searching for an answer to the same problem, apparently no straight forward method is present to do this. But, I think we can combine a Call Log content observer with PhoneStateListener to get the call duration.
We could set a flag in the shared prefs when an outgoing call is started, if anything changes in call log and our shared prefs flag is true we could get the call duration from the call log to see if the call was ever connected :)

You can Check these Duplicate questions:
How can my android app detect a dropped call?
Detecting outgoing call and call hangup event in android

Related

How to stop an ongoing phone authentication request with Firebase

I have added to my phone authentication to my sign up process, in a send code activity - which sends the sms code to confirm the phone authentication process. Then, I have also added a "go-back"/"return" button which moves the user back to the main activity.
If I make the following request which sends the user a sms code to his phone:
PhoneAuthProvider.verifyPhoneNumber(options);
I won't be able to make another request before the defined timeout duration ends. Therefore, I thought about the easy and not messy approach, that would be to cancel the ongoing request, but unfortunately couldn't find how to do so, if even possible nowadays. I have also saw the unanswered post here: Android Firebase OTP auth: Is there a way to cancel OTP code request programatically before the actual timeout?
Couldn't work with this, even though it's what I am looking for, but it has no related answers.
Note: I am programming my project with Java and not Kotlin.
I have also thought about the second approach, which is to save current activity's phone number and then extract it with onRestoreInstanceState and onSaveInstanceState, then resend a code sms again. But of course, it's much more complicated and messier.
It is possible to cancel an ongoing verification request by calling the verifyPhoneNumber method again with the same phone number, but with the forceResendingToken parameter set to null. This will cancel the previous request and allow to start a new one.
It is also possible to use the PhoneAuthProvider.getInstance() method to get a reference to the PhoneAuthProvider instance, and then call the verifyPhoneNumber method on that instance instead of calling it directly. This allows to call the verifyPhoneNumber method multiple times without canceling the previous request.
Timeout duration for verification requests is typically around 5 minutes, so if you want to allow the user to request a new code before the timeout expires, provide a way for them to do so, such as by adding a "Resend code" button to the app.
Overall, it's best to design apps in a way that minimizes the need for canceling ongoing verification requests, as this can lead to a confusing user experience. Instead, focus on providing clear instructions and options for the user, and consider using the getInstance method to avoid having to cancel requests altogether.

how to find out broadcast receiver is called?

I'm trying to use usb serial port but all example I've seen use broadcast receiver. in their code they give a pending intent to UsbSeialManager.requestPermission(pi). now i want to know if there is a way to see if onReceive() is called or not. and to wait for it.
I need a method that return correct usb(onReceive() is called)
P.S. I'm making a class for each connected usb.
Within the help of Log.d("key","value"); you can print the log to identify that onReceive() is called or not

Intercept incoming call in a rooted Android (Jelly Bean)

I'm looking to intercept calls in order to block all calls from numbers not stored in Contacts and to avoid all sorts of notifications set by default Phone app – in status bar, on its icon (number of missed calls), etc.
All devices are Samsung Galaxy Core Duos, so I have Blocking mode as an undesirable way of blocking all calls from numbers not stored in Contacts. My main problem is finding a way to disable (avoid) aforementioned notifications. I know I can empty my call log, and I am doing it, but notifications stay, both in status bar and on icon. That being said, I believe either both or none can be solved.
Is there a way to do this for rooted devices running Jelly Bean?
Since there's no proper way of using abortBroadcast() in this case, as android.intent.action.PHONE_STATE is not being received via an ordered broadcast (no system's sendOrderedBroadcast() call, like with received short message, but plain old sendBroadcast() instead), all receivers must receive this intent "at the same time".
To make my goal possibly impossible, as far as I can see, things start happening even before the broadcast. Furthermore, nothing "legally receivable" happens before the call to sendBroadcast(), as thoroughly yet briefly described in this blog post. By the way, this post was submitted in 2009. Has anything related to this problem changed since then?
Is it possible to solve this using shell? If yes, how?
The code that's emptying call log is the following:
context.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI, null, null);
I have permissions needed (for instance: WRITE_CALL_LOG, READ_CONTACTS, WRITE_CONTACTS) and this works. Call log shows to be empty when I touch Phone app icon or status bar notification.
I solved it using this piece of code:
Runtime runtime = Runtime.getRuntime();
try
{
runtime.exec("service call phone 5 \n");
}
catch (Exception e)
{
e.printStackTrace();
}
It marks call as ended, instead of marking it as missed, and ended calls do not show notifications of any kind.
If 5 doesn't work, try some other digits, like 4, 6, 8, etc.

Jain Sip processRequest method not being called

I am writing an application in Java to make calls and view when people are in calls, their phone is ringing or are idle, using the library Jain-Sip and at the moment am trying to correctly implement presence with SUBSCRIBE and NOTIFY messages. I am able to get presence data to be received, but after a while the presence data stops being displayed by my program.
I believe this is because the overridden method "processRequest" is not being called. This is the earliest point in the program where NOTIFY messages are being handled and not even the print statements are being output.
The bizarre thing about this is that the notify messages are being sent when I make calls, and the presence data is there. I know this because I have done Wireshark traces when running the program.
Note: No exceptions are occurring during execution of the program, to cause erroneous behaviour.
If anybody has any insight into why this is happening, I would be very grateful.
Thanks a lot,
Adam
Make sure you add your listener class correctly. The only other possible cause would be if the NOTIFY is unsolicited, which should not be the case but it happens. Try to enable this flag gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY. See more about it here https://jsip.ci.cloudbees.com/job/jsip/javadoc/gov/nist/javax/sip/SipStackImpl.html
Otherwise you will need to attach DEBUG logs to figure it out, could be malformed request or something of the sort.

Run AsyncTask every X second to update GPS position

I have a class that extends AsyncTask, which fetches the gps cordinates from the device.
I would like to keep the data updated, so my initial though was to call the class from a timer or a handler. Is this a smart way to implement it, or am i better off listening to the onLocationChanged and do my updates in there?
Hope you get the idea, otherwise ill elaborate.
Thanks!
An alarmManager will be a good solution here.
These allow you to schedule your application to be run at some point in the future.
When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running.
So when alarm gets triggered, call your execute() method of Async task.
For more info see this: http://developer.android.com/reference/android/app/AlarmManager.html
I also want to implement the same in my app in near future. If you get the solution, don't forget to update the post about how you implemented it.
Thank you.

Categories

Resources