我在我的應用程序中實現了運行時權限,但我無法做到顯示CALL_PHONE權限。我需要顯示兩個權限,read_contact和call_phone。我可以完美顯示read_contact,但不能獲得call_phone權限。我無法在運行時權限中顯示Manifest.permission.CALL_PHONE
我正在使用AVD仿真器進行測試。
一些幫助將是apreciate!
這是我的代碼:
callPesmission.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
requestCallPhonePermission();
}
});
contactPesmission.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
requestContactsPermission();
}
});
private void requestContactsPermission() {
String locationPermission = Manifest.permission.READ_CONTACTS;
int hasPermission = ContextCompat.checkSelfPermission(getActivity(), locationPermission);
String[] permissions = new String[] { locationPermission };
if (hasPermission != PackageManager.PERMISSION_GRANTED) {
requestPermissions(permissions, REQUEST_CONTACTS);
} else {
Toast.makeText(getActivity(), "We already have persmission", Toast.LENGTH_SHORT).show();
}
}
private void requestCallPhonePermission() {
String callPermission = Manifest.permission.CALL_PHONE;
int hasPermission = ContextCompat.checkSelfPermission(getActivity(), callPermission);
String[] permissions = new String[] { callPermission };
if (hasPermission != PackageManager.PERMISSION_GRANTED) {
requestPermissions(permissions, REQUEST_CALL_PHONE);
} else {
Toast.makeText(getActivity(), "We already have persmission", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case REQUEST_CONTACTS:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getActivity(), "READ_CONTACTS GRANTED", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "READ_CONTACTS DENIED", Toast.LENGTH_SHORT).show();
}
break;
case REQUEST_CALL_PHONE:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getActivity(), "CALL_PHONE GRANTED", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "CALL_PHONE DENIED", Toast.LENGTH_SHORT).show();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
看到你自己的答案:)發生在我們最好的可能拋出安全異常:)運行權限可以是疼痛 – Kushan
是的,絕對同意 –