繁体   English   中英

我想在 ACTION_CALL 的帮助下按下我的移动应用程序中的按钮来拨打紧急号码,但我没有。 为什么?

[英]i want to make call on an emergency number by pressing the button in my mobile app with help of ACTION_CALL but i didn't. why?

我想在 ACTION_CALL 的帮助下按下我的移动应用程序中的按钮来拨打紧急号码,但我没有。 为什么?

我在清单文件中实现了 CALL_PHONE 权限。

<uses-permission android:name="android.permission.CALL_PHONE"/>

这是我要调用的 java 代码。

public void makeCall(View v){
        if (ActivityCompat.checkSelfPermission(this,Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED){
            Toast.makeText(getApplicationContext(), "making call", Toast.LENGTH_LONG).show();
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_USER_ACTION);
            callIntent.setData(Uri.parse("tel:108"));
            startActivity(callIntent);
        }else{
            Toast.makeText(getApplicationContext(), "making call is not possible", Toast.LENGTH_LONG).show();
            ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.CALL_PHONE},MY_PERMISSIONS_REQUEST_CALL_PHONE);
        }
    }

此代码将我带到手机的默认拨号器。

如何在不使用默认拨号器的情况下直接通过我的应用拨打紧急号码?

 Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:"+123));//change the number

    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CALL_PHONE},12);
    }else{
        startActivity(callIntent);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM