Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Flip permission methods and rename them
  • Loading branch information
JulianKast committed Sep 4, 2022
commit cb1c48e1172481db5861bc9d1ecdda4989b0453b
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

private boolean checkBTPermission() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !checkPermission(Manifest.permission.BLUETOOTH_CONNECT);
/**
* Boolean method that checks API level and check to see if we need to request BLUETOOTH_CONNECT permission
* @return false if we need to request BLUETOOTH_CONNECT permission
*/
private boolean hasBTPermission() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? checkPermission(Manifest.permission.BLUETOOTH_CONNECT) : true;
}

private boolean checkPNPermission() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && !checkPermission(Manifest.permission.POST_NOTIFICATIONS);
/**
* Boolean method that checks API level and check to see if we need to request POST_NOTIFICATIONS permission
* @return false if we need to request POST_NOTIFICATIONS permission
*/
private boolean hasPNPermission() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ? checkPermission(Manifest.permission.POST_NOTIFICATIONS) : true;
}

private boolean checkPermission(String permission) {
Expand All @@ -57,10 +65,10 @@ private void requestPermission(String[] permissions, int REQUEST_CODE) {

private @NonNull String[] permissionsNeeded() {
ArrayList<String> result = new ArrayList<>();
if (checkBTPermission()) {
if (!hasBTPermission()) {
result.add(Manifest.permission.BLUETOOTH_CONNECT);
}
if (checkPNPermission()) {
if (!hasPNPermission()) {
result.add(Manifest.permission.POST_NOTIFICATIONS);
}
return (result.toArray(new String[result.size()]));
Expand Down