安卓:请电话从服务 [英] Android: Make phone call from service

查看:113
本文介绍了安卓:请电话从服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从一个服务里面打个电话。在code我用的是:

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?

和我怎么能做出这样一件code运行中的主要活动?

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

推荐答案

试图为从服务中拨打电话:

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

这篇关于安卓:请电话从服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆