7

I try to make a phone call from inside a service. The code I use is:

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

and it works well from inside the main activity, but not from the service. The error occurs on the last line. Is it not possible to make a call inside a service?

And how could I make this piece of code run on the main activity?

Kara
  • 6,115
  • 16
  • 50
  • 57
DominicM
  • 2,186
  • 5
  • 24
  • 42

2 Answers2

9

try as to make a phone call from inside a service:

Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
startActivity(intent);
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • 2
    This doesn't work for me, I get error: android.content.ActivityNotFoundException: `No Activity found to handle Intent { act=android.intent.action.CALL flg=0x10000004 }` – T.Coutlakis Feb 23 '14 at 14:47
-1

check in the manifest if the service is outside of any activity