在 Android 中拨打 911

发布于 2024-10-21 23:53:28 字数 398 浏览 9 评论 0原文

我想使用 Android SDK 拨打紧急号码。

我正在使用以下代码拨打号码(911)。此代码适用于除 911(紧急号码)之外的所有号码。当我使用 911 时,它会显示我不想要的拨号屏幕。是否有任何程序可以在不打开拨号器的情况下拨打 911,或者我们可以阻止用户在拨号器屏幕中编辑号码吗?

Uri callUri = Uri.parse("tel://911");
Intent callIntent = new Intent(Intent.ACTION_DIAL,callUri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_USER_ACTION);
startActivity(callIntent);

I want to call Emergency number using Android SDK.

I am using following code to call the number (911). This code works fine for all the numbers except 911 (Emergency Number). When I use 911, then it shows the dialer screen that I don't want. Is there any procedure to call 911 without open the dialer or can we stop the user to edit the number in Dialer screen?

Uri callUri = Uri.parse("tel://911");
Intent callIntent = new Intent(Intent.ACTION_DIAL,callUri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_USER_ACTION);
startActivity(callIntent);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

娜些时光,永不杰束 2024-10-28 23:53:28

提供的代码应该已经可以实现此目的,但您需要 CALL_PHONE 和 CALL_PRIVILEGED 权限才能拨打紧急号码而不显示拨号盘。

Android 参考 - 清单权限 CALL_PRIVILEGED

将其添加到清单后,您应该能够使用相同的代码使用 ACTION_CALL 代替直接拨号:

Uri callUri = Uri.parse("tel://911");
Intent callIntent = new Intent(Intent.ACTION_CALL,callUri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_USER_ACTION);
startActivity(callIntent);

The code provided should already work for this, but you need the CALL_PHONE and CALL_PRIVILEGED permission to dial emergency numbers without showing the dial-pad.

Android Reference - Manifest Permission CALL_PRIVILEGED

Once that is added to the manifest, you should be able to use the same code using the ACTION_CALL instead to direct dial:

Uri callUri = Uri.parse("tel://911");
Intent callIntent = new Intent(Intent.ACTION_CALL,callUri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_USER_ACTION);
startActivity(callIntent);
青芜 2024-10-28 23:53:28

Action_Dial将打开拨号盘,Action_Call将直接调用..

但是,引用 ACTION_CALL

注意:此意图不能用于
拨打紧急电话号码。应用领域
可以使用拨打紧急号码
但是,ACTION_DIAL。

Action_Dial will open the dialpad, Action_Call will call directly..

However, a quote from ACTION_CALL:

Note: this Intent cannot be used to
call emergency numbers. Applications
can dial emergency numbers using
ACTION_DIAL, however.

梦醒时光 2024-10-28 23:53:28

假设将 Intent.ACTION_CALL 替换为 Intent.ACTION_DIAL,这将呼叫号码,而不会在拨号盘上显示该号码。

Say Intent.ACTION_CALL insted of Intent.ACTION_DIAL this will call number without showing it on dial pad.

各空 2024-10-28 23:53:28
private fun startCall() {
    val callIntent = Intent(Intent.ACTION_CALL)
    callIntent.data = Uri.parse("tel:$phoneEmergency")
    startActivity(callIntent)
}

override fun onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<out String>,
    grantResults: IntArray
) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    if(requestCode == REQUEST_PHONE_CALL) startCall()
}

en el oncreate uso los 绑定

binding.btnEmergency.setOnClickListener {

        if(ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CALL_PHONE), REQUEST_PHONE_CALL)
        }else{
            startCall()
        }
private fun startCall() {
    val callIntent = Intent(Intent.ACTION_CALL)
    callIntent.data = Uri.parse("tel:$phoneEmergency")
    startActivity(callIntent)
}

override fun onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<out String>,
    grantResults: IntArray
) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    if(requestCode == REQUEST_PHONE_CALL) startCall()
}

en el oncreate uso los bindings

binding.btnEmergency.setOnClickListener {

        if(ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CALL_PHONE), REQUEST_PHONE_CALL)
        }else{
            startCall()
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文