我们如何通过单击TextView来进行android调用?

时间:2016-12-19 11:04:38

标签: android

我在点击TextView以获取来自android的电话后出现了一些问题。任何人都可以建议我为什么......来自

我的代码:

public void goForTheCall() {
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse(helpDesk));
    startActivity(callIntent);

}

在startaActivity上,显示红色错误,例如“呼叫需要权限,可能被用户拒绝:代码应明确检查权限是否可用(使用checkPermission)”或明确处理潜力SecurityException ” 和我的manifestfile

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

2 个答案:

答案 0 :(得分:1)

问题在于Android 6在运行时请求权限。因此,您应该关注developer.android.com上的教程here

    if (ContextCompat.checkSelfPermission(thisActivity,
                Manifest.permission.CALL_PHONE)
        != PackageManager.PERMISSION_GRANTED) {

    // Should we show an explanation?
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
            Manifest.permission.CALL_PHONE)) {

        // Show an explanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response! After the user
        // sees the explanation, try again to request the permission.

    } else {

        // No explanation needed, we can request the permission.

        ActivityCompat.requestPermissions(thisActivity,
                new String[]{Manifest.permission.CALL_PHONE},
                MY_PERMISSIONS_REQUEST_CALL_PHONE);

        // MY_PERMISSIONS_REQUEST_CALL_PHONE is an
        // app-defined int constant. The callback method gets the
        // result of the request.
    }
}

答案 1 :(得分:0)

请检查marshmallow运行时权限。如果您拒绝了该权限,则必须转到设置并启用权限。

int checkPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE);
    if (checkPermission != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(
                        this,
                        new String[]{Manifest.permission.CALL_PHONE},
                        REQUEST_CALL_PHONE);
            } else {
                customDialog(CallChoosyActivity.this);
            }