如何从后台服务拨打电话?

问题描述 投票:-1回答:1

我是新来的android请帮忙。 我试过用这个代码......

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个回答
0
投票

请尝试下面的代码。

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

您将从服务qazxsw poi方法获得上下文。在qazxsw poi的地方,可以使用qazxsw poi

© www.soinside.com 2019 - 2024. All rights reserved.