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.
Related
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.
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.
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?)
I see there are plenty of examples on how to call a number, and I also see that I can only have it pop up the dialer to go to an emergency number. But in all those example they hard coded "911" as the number to use. well this works fine in the US but since android phones are sold in other countries and thusly there is the possibility that my app will be bought by someone not in the US, or that someone who lives in the us may take their phone overseas; is there a way then my app can realize it's not in the us and thusly has to use a different number to call emergency service and what that number would be?
So to sum up I'd like to know if there is a way I can have it so when the app goes to bring up the dialer with the emergency number for the country it's in, with out having to know that number at complie time?
According to the source for PhoneNumberUtils.isEmergencyNumber():
String numbers = SystemProperties.get("ril.ecclist");
if (TextUtils.isEmpty(numbers)) {
// then read-only ecclist property since old RIL only uses this
numbers = SystemProperties.get("ro.ril.ecclist");
}
numbers will be a comma separated list.
I know that with the telephony manager listen, you can listen for 3 different states. Iknow that CALL_STATE_OFFHOOK indicates that there is at least one call that is dialing, active, etc. My question is- with the telephony manager, is there a way to determine what number the phone is off hook with? I thought getLine1Number() might return that phone number that is being dialed, but it is not what I expect. I am working with 2 emulators, and added a log line so that I could see what that method is doing. When dialing another emulator, I expected getLine1Number() to return 5554, but it was 15555218135. Perhaps there is another method I should be using instead? Do I need to be into the source code to get the information I want?
Clearly, getLine1Number() is returning the phone's number. I currently have a work around of having the user use the program to initiate a call. They enter the number to dial in a text box and that way I can capture the number.