ACTION_CALL无法在移动设备上运行,但它在模拟器中运行

时间:2017-05-16 04:55:34

标签: android

我正在为我的应用程序使用Action_call,它在我的模拟器中工作正常,当我在我的手机中运行相同的代码时它无法正常工作并且它没有打开拨号盘 我也获得了清单的许可,但没有用。这是代码

button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent myIntent = new Intent(Intent.ACTION_DIAL);
                String phNum = "tel:9741437389";
                myIntent.setData(Uri.parse(phNum));
                if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                    // TODO: Consider calling
                    //    ActivityCompat#requestPermissions
                    // here to request the missing permissions, and then overriding
                    //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                    //                                          int[] grantResults)
                    // to handle the case where the user grants the permission. See the documentation
                    // for ActivityCompat#requestPermissions for more details.
                    return;
                }
                startActivity(myIntent);
            }
        });

2 个答案:

答案 0 :(得分:2)

ACTION_CALL和ACTION_DIAL在android中是不同的东西。

1.in ACTION_CALL intent you are directly place call.

2.in ACTION_DIAL intent you call dial screen.

ACTION_DIAL从不拨打电话。在这里你不需要提供任何许可。

答案 1 :(得分:0)

我不确定,如果您使用的api版本大于23,则需要提供运行时权限。

1)请检查您是否使用api版本23表示添加运行时权限。   2)如需添加运行时权限,请参阅此视图。

http://www.truiton.com/2016/04/obtaining-runtime-permissions-android-marshmallow-6-0/

http://www.journaldev.com/10409/android-handling-runtime-permissions-example

https://www.simplifiedcoding.net/android-marshmallow-permissions-example/