Android Intent ACTION_CALL not making a phone call
Asked Answered
U

4

6

In my Android application I would like to make a phone call automatically when user click the button. I have used the below set of code to achieve this functionality

Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:911"));
                startActivity(intent);

and in my AndroidManifest.xml I have added this <uses-permission android:name="android.permission.CALL_PHONE" /> permission too.

But it is just opening the dialer pad with the given 911 no instead of making a phone call.

Unseal answered 6/5, 2016 at 13:0 Comment(2)
change your phno="tel:10digits"; and try again.Hootenanny
that is the only behaviour of ACTION_CALLGobo
A
9

At least in the US, 911 is an emergency number. CALL_PHONE is insufficient to call that number. There is a separate permission for that (CALL_PRIVILEGED?), one that cannot be held by ordinary SDK apps.

UPDATE: I remembered correctly. Here is the Android 6.0 platform manifest entry for that permission:

<!-- @SystemApi 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.
         <p>Not for use by third-party applications. -->
    <permission android:name="android.permission.CALL_PRIVILEGED"
        android:protectionLevel="signature|privileged" />
Ancestress answered 6/5, 2016 at 13:2 Comment(13)
even though I added <uses-permission android:name="android.intent.action.CALL_PRIVILEGED"></uses-permission> in AndroidManifest.xml it doesn't automatically call 911 no. but it is calling other numbers.Unseal
@Jamal: That is because you cannot hold the CALL_PRIVILEGED permission, unless you are building your own custom ROM.Ancestress
My application's targetSdkVersion is 19. ` <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" />` If add <permission android:name="android.permission.CALL_PRIVILEGED" android:protectionLevel="signature|privileged" /> this line in my AndroidManifest.xml, it shows error: Error: String types not allowed (at 'protectionLevel' with value 'signature| privileged').Unseal
@Jamal: You cannot add that <permission> element to your app. That is a platform-defined permission. You cannot hold the CALL_PRIVILEGED permission, unless you are building your own custom ROM.Ancestress
So, I couldn't directly call a emergency no 911 from my application. may I right?Unseal
@Jamal: Correct. Calls to emergency numbers can only be made by apps that are part of the device ROM or were signed with that ROM's signing key.Ancestress
could you please provide any document regarding this,it will help me.Unseal
Let us continue this discussion in chat.Unseal
HI, just wanted to know if the solution is still applicable?Squeeze
@Ali: There is no solution that I am aware of -- unless your app can hold privileged permissions, it cannot place calls to emergency numbers.Ancestress
@Ancestress confirmed by CALL_PRIVILEGED granting to my own phone app, the above method is applicable but, emergency call screen is not showing while dialing,Squeeze
@Ali: Sorry, I do not know anything about that.Ancestress
@Ancestress np mate :)Squeeze
T
0

Try with Intent.ACTION_DIAL instead. This is the code that I have used and it worked well:

    Intent callIntent = new Intent(Intent.ACTION_DIAL); 
 callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_USER_ACTION);    
     callIntent.setData(Uri.parse("tel://911"));
     startActivity(callIntent);

Updated by adding FLAG_ACTIVITY_NO_USER_ACTION. Test it and see if it works. I see in you included the permission part of your Manifest. Please consider including your entire Manifest file so we can see that everything is OK there as well.

Twandatwang answered 6/5, 2016 at 13:15 Comment(2)
Noted. So did it give an error or does it show the dialer with the number? I updated the answer - specifically, I added a new Flag. Hopefully it helps now.Twandatwang
No, ishmaelMakitla it is just opening Dialer pad alone,not making a phone call. I have tried with ACTION_CALLUnseal
D
0

You have to give permission in app permissions set telephone to true.

Determinate answered 11/5, 2019 at 5:48 Comment(1)
please make your answer more specificallySad
P
-1

I also had the same problem. Most probably it may be because our device grant the permission to that app then it may work. Just go to settings and grant the permission of "telephone".

Propitiatory answered 7/12, 2017 at 11:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.