Is it possible using the telephony (or other) APIs on an unrooted Android phone, for an application to listen for the Telephony intents (ringing / Incoming-call), and if calling party matches a criteria (such as, from a black-list), disconnect the call, without requiring a confirmation by the user ?
Also, it is possible for an application on such (an unrooted) Android phone to initiate an outgoing call without user's intervention (s.a. at a particular time or when certain conditions are met) ?
In my research so far, I've found that I'd have to use a BroadcastReceiver with the right priority, to be able to "trap" the 'ringing event', and use ITelephony.aidl to reject the call. However, it wasn't clear if I can do the latter on an unrooted phone or not.
For the second requirement, it is not clear if app can make an going call -- again, on an unrooted Android phone.
Is it possible using the telephony (or other) APIs on an unrooted Android phone, for an application to listen for the Telephony intents (ringing / Incoming-call), and if calling party matches a criteria (such as, from a black-list), disconnect the call, without requiring a confirmation by the user ?
You can easily get the state of the current call. However, hanging up yourself without user interaction is only possible through reflection.
Also, it is possible for an application on such (an unrooted) Android phone to initiate an outgoing call without user's intervention (s.a. at a particular time or when certain conditions are met) ?
You can dial a number without asking the user by using:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
Keep in mind that you must have the android.permission.CALL_PHONE permission, and that replacing ACTION_CALL with ACTION_DIAL will ask the user to confirm. ACTION_CALL places the call directly.
Related
In my app I am trying to intercept all outgoing calls starting with 00 string. I used Telephony Manager for the same to get outgoing number and then intercept it. All code was working properly before Android 9.0. But in Android Pie once i made call then my app crashed because i am not getting User Dialed number in Receiver.
"Without the READ_CALL_LOG permission, however, the phone number field
that's provided in PHONE_STATE_CHANGED broadcasts and through
PhoneStateListener is empty."
So you have to ensure the user grants permission for reading phone number before you try to access any dialed number.
Also you have to keep a check and a backup plan in case user refuses permission. Your app should handle such case well so as to avoid any null pointers.
I wrote an application which has the capability of hanging up phone calls when they are received. In order to that I'm using the telephony manager and this permission is required:
android.permission.MODIFY_PHONE_STATE
However, this permission makes my app a system app and therefore I won't be able to place it in the play store later.
But I've seen apps in the play store that successfully block incoming calls ("Calls Blacklist" for example).
I wonder, does anyone know what API these apps are using in order to block an incoming call and also allow these apps in the play store ?
Thanks.
You need to make use of Broadcastreceiver class.
and also need to add this line in manifest to get persmission.
<uses-permission android:name="android.permission.READ_PHONE_STATE">
follow this.
http://www.tutorialforandroid.com/2009/01/get-phone-state-when-someone-is-calling_22.html
Make sure TelephonyManager.CALL_STATE_RINGING is only incoming call.
You cannot detect outgoing call state whether it is ringing or answered.
for outgoing there only two states:
TelephonyManager.CALL_STATE_IDLE
&
TelephonyManager.CALL_STATE_OFFHOOK
In Android Open Source Project, a lot of core API declarations have an integer parameter userId in the end. I traced back and figured out the integer comes from a class called "UserHandle.java". There is a simple comments saying this class represents a user on the device. It still confuses me. Why do we need such a class? What's the difference between different values of the class, such as "USER_OWNER", "USER_CURRENT", "USER_CURRENT_OR_SELF"?
Thanks in advance!!!
Ever since Jelly Bean, Android platform has supported multiple users. This means that multiple users may be able to use one device, yet not be able to access other user's files or communicate with another user's app.
The first user on the device is user 0. The rest start their numbering from 10,11,... (In JB the numbering was 1,2...).
USER_OWNER is user 0.
He has some extra privileges over the other users (mostly access certain settings that others can't or uninstall an app for all users).
Multiple users on one device requires that only one user can be active in a specific point in time, this user is referred to as USER_CURRENT (since Kitkat().
In general one user's application can't send a broadcast message or an Intent to other user's apps.
Only apps with system permissions can do that (for example when the battery is running low, an intent will be sent to all).
Whenever you send an Intent from your app, the system service verifies whether this is a valid Intent i.e. if its supposed to reach all users then it's not.
This means that even if you were to use a certain api with the wrong userId (for example you force userId=0 even though this is user 10), then your call will receive a SecurityException.
To avoid such exceptions, there is also the option to send an Intent with USER_CURRENT_OR_SELF.
This means you're trying to send to the current user, but if he's not allowed to receive the Intent, let the same user who sent the Intent receive it.
The Android docs for the CALL_PHONE permission reads:
"Allows an application to initiate a phone call without going through the Dialer
user interface for the user to confirm the call being placed."
Also this message is prompted to the user when he installs the app.
Reading that the application may start hidden calls can possibly discourage installation for some users.
Since my app does NOT start hidden calls, I wonder if there is a way to limit this behaviour, possibly with a more strict permission, to avoid displaying that dreadful message to the user.
Here is my corrected solution:
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:" + 1234));
startActivity(callIntent);
This doesn't require any permissions and just open the dialer. Should be exactly that what you were looking for.
I don't think it's possible. There are 2 permissions associated with phone calls (CALL_PHONE, CALL_PRIVILEGED) with CALL_PHONE being the less restrict one. Google Play will always show that discouraging description for any application holding these permissions.
If this permission is really important for your application, leave it as it is. But opening the dialer instead of calling is a much better option for the user experience (In most of the cases), so try using it instead (You said you're notifying the user anyway... So why can't you show the dialer instead of that notification?)
What is difference between permissions CALL_PHONE and CALL_PHONE_PRIVLEGED. After reading there definitions it appears they do more or less the same things.
CALL_PHONE: Allows an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call being placed.
CALL_PRIVILEGED: Allows an application to call any phone number, including emergency numbers, without going through the Dialer user interface for the user to confirm the call being placed.
Can someone please explain the minute difference between the two?
any phone number, including emergency numbers
"Can dial 911" (or other emergency numbers, as valid in the specific location - e.g. 112 in EU)
You probably don't want just any ol' app calling the police of its own accord.