Android: Make phone call from service

 ̄綄美尐妖づ 提交于 2019-12-01 02:41:13

问题


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?


回答1:


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);



回答2:


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



来源:https://stackoverflow.com/questions/11915086/android-make-phone-call-from-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!