【问题标题】:How to make calls from a Background Service?如何从后台服务拨打电话?
【发布时间】:2017-12-21 15:05:39
【问题描述】:

我是安卓新手,请帮忙。
我尝试使用此代码...

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

没用:它突然停止了。
我提到了必要的权限

【问题讨论】:

标签: android service background call


【解决方案1】:

请尝试以下代码。

        new Handler().post(new Runnable() {
            @Override
            public void run() {
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);
context.startActivity(intent);
            }
        });

您将从服务onStart() 方法中获取上下文。 Context的inPlace,可以使用getApplicationContext()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-29
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 2022-06-12
    • 2023-03-14
    相关资源
    最近更新 更多