Android 我正在检查棉花糖的通话许可

Android 我正在检查棉花糖的通话许可,android,Android,当我运行应用程序时,它会在logcat中显示这一点 java.lang.SecurityException:权限拒绝:启动意图{act=android.Intent.action.CALL dat=tel:xxxxxxxxx cmp=android/com.android.internal.app.ResolverActivity} 来自具有吊销权限的进程记录{2dd511f 24656:com.marg.pharmanxt/u0a158}(pid=24656,uid=10158),androi

当我运行应用程序时,它会在logcat中显示这一点

java.lang.SecurityException:权限拒绝:启动意图{act=android.Intent.action.CALL dat=tel:xxxxxxxxx cmp=android/com.android.internal.app.ResolverActivity} 来自具有吊销权限的进程记录{2dd511f 24656:com.marg.pharmanxt/u0a158}(pid=24656,uid=10158),android.permission.CALL_PHONE 位于android.os.Parcel.readException(Parcel.java:1599) 位于android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2771)的android.os.Parcel.readException(Parcel.java:1552)


根据此更改您的权限请求代码

public void checkPermissions() {

    Log.i(TAG, " Checking permissions.");

    // Verify that all required contact permissions have been granted.
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

        // Contacts permissions have not been granted.
        Log.i(TAG, "Call Phone permissions has NOT been granted. Requesting permissions.");
        requestPermissions();

    } else {

        // Contact permissions have been granted. Show the contacts fragment.
        Log.i(TAG,
                "Contact permissions have already been granted");
        showContactDetails();
    }
}


public void customDialog(Context ctx) {

    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder = new AlertDialog.Builder(ctx, android.R.style.Theme_Material_Light_Dialog_Alert);
        builder.setMessage("Call permissions are needed to demonstrate access").setNeutralButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,
                                        int whichButton) {
                        ActivityCompat.requestPermissions(CallChoosyActivity.this, Permissions, REQUEST_CALL_PHONE);
                    }
                });

        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    } else {
        builder = new AlertDialog.Builder(ctx);
        builder.setMessage("Call permissions are needed to demonstrate access").setNeutralButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,
                                        int whichButton) {

                    }
                });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }

}

public void requestPermissions() {

    // BEGIN_INCLUDE(contacts_permission_request)
    if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CALL_PHONE)) {

        // Provide an additional rationale to the user if the permission was not granted
        // and the user would benefit from additional context for the use of the permission.
        // For example, if the request has been denied previously.
        Log.i(TAG, "Displaying call permission rationale to provide additional context.");

        customDialog(CallChoosyActivity.this);
    } else {
        // Contact permissions have not been granted yet. Request them directly.
        ActivityCompat.requestPermissions(this, Permissions, REQUEST_CALL_PHONE);
    }
    // END_INCLUDE(contacts_permission_request)
}


@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                       @NonNull int[] grantResults) {

    if (requestCode == REQUEST_CALL_PHONE) {
        Log.i(TAG, "Received response for contact permissions request.");

        // We have requested multiple permissions for contacts, so all of them need to be
        // checked.
        if (PermissionUtil.verifyPermissions(grantResults)) {
            // All required permissions have been granted, display contacts fragment.
            showContactDetails();
        } else {
            Log.i(TAG, "Contacts permissions were NOT granted.");
        }

    } else {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}

public void showContactDetails() {
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + PartyTabsActivity.numbersList.get(0)));
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

        return;
    }
    startActivity(callIntent);
}

将您的
onRequestPermissionsResult保持原样

根据此更改您的权限请求代码

public void checkPermissions() {

    Log.i(TAG, " Checking permissions.");

    // Verify that all required contact permissions have been granted.
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

        // Contacts permissions have not been granted.
        Log.i(TAG, "Call Phone permissions has NOT been granted. Requesting permissions.");
        requestPermissions();

    } else {

        // Contact permissions have been granted. Show the contacts fragment.
        Log.i(TAG,
                "Contact permissions have already been granted");
        showContactDetails();
    }
}


public void customDialog(Context ctx) {

    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder = new AlertDialog.Builder(ctx, android.R.style.Theme_Material_Light_Dialog_Alert);
        builder.setMessage("Call permissions are needed to demonstrate access").setNeutralButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,
                                        int whichButton) {
                        ActivityCompat.requestPermissions(CallChoosyActivity.this, Permissions, REQUEST_CALL_PHONE);
                    }
                });

        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    } else {
        builder = new AlertDialog.Builder(ctx);
        builder.setMessage("Call permissions are needed to demonstrate access").setNeutralButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,
                                        int whichButton) {

                    }
                });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }

}

public void requestPermissions() {

    // BEGIN_INCLUDE(contacts_permission_request)
    if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CALL_PHONE)) {

        // Provide an additional rationale to the user if the permission was not granted
        // and the user would benefit from additional context for the use of the permission.
        // For example, if the request has been denied previously.
        Log.i(TAG, "Displaying call permission rationale to provide additional context.");

        customDialog(CallChoosyActivity.this);
    } else {
        // Contact permissions have not been granted yet. Request them directly.
        ActivityCompat.requestPermissions(this, Permissions, REQUEST_CALL_PHONE);
    }
    // END_INCLUDE(contacts_permission_request)
}


@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                       @NonNull int[] grantResults) {

    if (requestCode == REQUEST_CALL_PHONE) {
        Log.i(TAG, "Received response for contact permissions request.");

        // We have requested multiple permissions for contacts, so all of them need to be
        // checked.
        if (PermissionUtil.verifyPermissions(grantResults)) {
            // All required permissions have been granted, display contacts fragment.
            showContactDetails();
        } else {
            Log.i(TAG, "Contacts permissions were NOT granted.");
        }

    } else {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}

public void showContactDetails() {
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + PartyTabsActivity.numbersList.get(0)));
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

        return;
    }
    startActivity(callIntent);
}

请保留您的
onRequestPermissionsResult
原样

您是否正在检查棒棒糖或棉花糖设备?我正在检查棉花糖设备?您是否正在检查棒棒糖或棉花糖设备?我正在检查棉花糖设备