2

for some reason ACTION_CALL is not working in my app. I have added the permission to the manifest:

  <uses-permission android:name="android.permission.CALL_PHONE" />

Here is where I call action_call from my main activity:

case R.id.button2:
            intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:(+44)12345678900"));
            if(ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)!= PackageManager.PERMISSION_GRANTED){
                Toast.makeText(this, "No permission to call!", Toast.LENGTH_SHORT).show();
                return;
            }
startActivity(intent);
            break;

Each time the toast shows and the number is not called. Any help would be appreciated! :)

manifest code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.adamw_000.lab_1_intents" >

<uses-permission android:name="android.permission.CALL_PHONE" />
AdamW95
  • 51
  • 1
  • 5
  • Please show the code where you are calling `requestPermissions()`, to ask the user for this permission. Also, are you sure that you have your `` element in the proper spot in the manifest? BTW, I suggest removing the space in the `tel:` string, as that might confuse the dialer, when you get to that point. – CommonsWare Feb 09 '16 at 18:47
  • Have removed the space and added the code for the manifest permissions, I don't call request permission as the permission is already given in the manifest – AdamW95 Feb 09 '16 at 18:53
  • 1
    "I don't call request permission as the permission is already given in the manifest" -- then that's your bug. The point behind calling `checkSelfPermission()` is to see if the user granted the permission. On Android 6.0, if your `targetSdkVersion` is 23 or higher, you do *not* get this permission automatically and need to request it. See the duplicate question for more details. – CommonsWare Feb 09 '16 at 18:57
  • Im using api 22 edit: nvm i see where you're going with this cheers – AdamW95 Feb 09 '16 at 18:58

1 Answers1

1

Maybe you should add the startActivity() as

startActivity(intent);

EDIT

I used this code :

intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel: (+44)12345678900"));
startActivity(intent);

And it works well...

Try this, it is working as well for me but it's using ACTION_DIAL:

public static Intent newPhoneCallIntent(String phoneNumber){
    Intent callintent = new Intent(Intent.ACTION_DIAL);
    callintent.setData(Uri.parse("tel:"+phoneNumber));
    return callintent;
}

And in your Button add this : startActivity(newPhoneCallIntent("(+44)12345678900"));

Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148