1

I followed the code found in this thread, How to make a phone call in android and come back to my activity when the call is done?

My code is the following:

When press button:

   Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("1337")); 

I also added

 android:name="android.permission.CALL_PHONE"> to user permissions

But nothing happens when I press the button.

Community
  • 1
  • 1
jojo
  • 27
  • 6

1 Answers1

2

Just add the tel: prefix to the number. I.e: ...(Uri.parse("tel:" + Number));

Then add the line:

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Now you are ready to to start the system "Call Activity" through your intent:
Something like:

getApplicationContext().startActivity(intent);
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • no that did not work. Ive checked some other threads and in them they have to start activitys and stuff.. do I need to do that aswell? I chos this code cause it was the shortest but it doesnt work. – jojo Oct 12 '14 at 12:28
  • this is my code for the button right now: button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel"+5554")); } }); – jojo Oct 12 '14 at 12:30
  • Of course you have to start the "Call Activity" through the intent. Or you would not prepare an intent. You miss something like `getApplicationContext().startActivity(intent);` And don't forget the **:** between **tel** and your number – Phantômaxx Oct 12 '14 at 12:30
  • Ok when I add that line I get this error: "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?" Something tells me this is not what I want o.O – jojo Oct 12 '14 at 12:39
  • Sure, you want it. It asks you if you want to launch a new intent, which is exactly what you want. I forgot to mention you have to add this line before starting the intent: `intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);` – Phantômaxx Oct 12 '14 at 12:42