如何从服务中拨打拨号程序?

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

我正在使用此this dialer example作为地下室。我从应该拨打电话的地方添加了一些服务(前景)。我该怎么做?

我在Service(onStartCommand)中有这个

    if (checkSelfPermission(this, CALL_PHONE) == PERMISSION_GRANTED) {
        val uri = "SOMENUMBER".toUri()
        startActivity(Intent(Intent.ACTION_CALL, uri).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
    }

但是我不服务。错误日志:

Process: *.*.*, PID: 2789
java.lang.RuntimeException: Unable to start service *.*.*.*.Service@ab2ea53 with Intent { cmp=*.*.*/.*.Service (has extras) }: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=PHONENUMBER flg=0x10000000 }

我应该怎么做才能使其正常工作?哪种方法更正确(如果mays> 1)?

android kotlin service phone-call android-dialer
1个回答
0
投票

"SOMENUMBER".toUri()

应该是

"tel:SOMENUMBER".toUri()

https://developer.android.com/reference/android/content/Intent.html#ACTION_CALL

输入:如果没有,则启动一个空的拨号程序; else getData()是要拨打的电话号码的URI或tel:显式电话号码的URI。

[其他相关问题:

Call intent in Android

Android Intent.ACTION_CALL, Uri

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