Android: make a phone call from a service

I'm trying to make a phone call from a service. The code I'm using is:

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

and it works well from within the main action, but not from the service. Error on the last line. Unable to call the service?

And how can I make this piece of code included in the main action?

+5
source share
2 answers

try making a phone call from the 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);
+8
source

Check the manifest if the service is outside of any activity.

-3
source

All Articles