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.

Jamal
  • 976
  • 2
  • 14
  • 39

4 Answers4

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" />
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • even though I added `` in AndroidManifest.xml it doesn't automatically call `911` no. but it is calling other numbers. – Jamal May 06 '16 at 13:22
  • @Jamal: That is because you cannot hold the `CALL_PRIVILEGED` permission, unless you are building your own custom ROM. – CommonsWare May 06 '16 at 13:24
  • My application's `targetSdkVersion` is `19`. ` ` If add `` this line in my `AndroidManifest.xml`, it shows `error: Error: String types not allowed (at 'protectionLevel' with value 'signature| privileged').` – Jamal May 06 '16 at 14:03
  • @Jamal: You cannot add that `` 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**. – CommonsWare May 06 '16 at 14:06
  • So, I couldn't directly call a emergency no `911` from my application. may I right? – Jamal May 06 '16 at 14:10
  • @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. – CommonsWare May 06 '16 at 14:13
  • could you please provide any document regarding this,it will help me. – Jamal May 06 '16 at 14:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/111270/discussion-between-jamal-and-commonsware). – Jamal May 07 '16 at 05:09
  • HI, just wanted to know if the solution is still applicable? – Ali Apr 27 '22 at 06:00
  • @Ali: There is no solution that I am aware of -- unless your app can hold privileged permissions, it cannot place calls to emergency numbers. – CommonsWare Apr 27 '22 at 11:19
  • @CommonsWare confirmed by CALL_PRIVILEGED granting to my own phone app, the above method is applicable but, emergency call screen is not showing while dialing, – Ali Apr 27 '22 at 11:47
  • @Ali: Sorry, I do not know anything about that. – CommonsWare Apr 27 '22 at 12:13
  • @CommonsWare np mate :) – Ali Apr 28 '22 at 08:41
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.

ishmaelMakitla
  • 3,784
  • 3
  • 26
  • 32
  • 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. – ishmaelMakitla May 06 '16 at 14:25
  • No, ishmaelMakitla it is just opening Dialer pad alone,not making a phone call. I have tried with `ACTION_CALL` – Jamal May 07 '16 at 05:24
0

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

-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".