Skip to content

Commit

Permalink
Request notification permission on Android 13+
Browse files Browse the repository at this point in the history
  • Loading branch information
farmerbb committed Sep 8, 2024
1 parent 928d0ea commit 88aeca9
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ private CompatUtils() {}
public static boolean isImeVisible(View view) {
return false;
}

public static void grantNotificationPermissionIfNeeded(Activity activity) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ private CompatUtils() {}
public static boolean isImeVisible(View view) {
return false;
}

public static void grantNotificationPermissionIfNeeded(Activity activity) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.farmerbb.taskbar.util;

// Utility class meant for compatibility between the Android-x86 version of Taskbar (compiled with SDK 28)
// and the Play Store version of Taskbar (compiled with SDK 30).
// and the Play Store version of Taskbar (compiled with SDK 34).
// TODO Do not make changes to this file without making corresponding changes to the Android-x86 version.

import android.os.Build;
Expand All @@ -31,4 +31,6 @@ public static boolean isImeVisible(View view) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
&& view.getRootWindowInsets().isVisible(WindowInsets.Type.ime());
}

public static void grantNotificationPermissionIfNeeded(Activity activity) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.farmerbb.taskbar.util;

// Utility class meant for compatibility between the Android-x86 version of Taskbar (compiled with SDK 28)
// and the Play Store version of Taskbar (compiled with SDK 30).
// and the Play Store version of Taskbar (compiled with SDK 34).
// TODO Do not make changes to this file without making corresponding changes to the Android-x86 version.

import android.os.Build;
Expand All @@ -31,4 +31,6 @@ public static boolean isImeVisible(View view) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
&& view.getRootWindowInsets().isVisible(WindowInsets.Type.ime());
}

public static void grantNotificationPermissionIfNeeded(Activity activity) {}
}
14 changes: 12 additions & 2 deletions app/src/compat-34/java/com/farmerbb/taskbar/util/CompatUtils.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2020 Braden Farmer
/* Copyright 2024 Braden Farmer
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,9 +16,12 @@
package com.farmerbb.taskbar.util;

// Utility class meant for compatibility between the Android-x86 version of Taskbar (compiled with SDK 28)
// and the Play Store version of Taskbar (compiled with SDK 30).
// and the Play Store version of Taskbar (compiled with SDK 34).
// TODO Do not make changes to this file without making corresponding changes to the Android-x86 version.

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.view.View;
import android.view.WindowInsets;
Expand All @@ -31,4 +34,11 @@ public static boolean isImeVisible(View view) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
&& view.getRootWindowInsets().isVisible(WindowInsets.Type.ime());
}

public static void grantNotificationPermissionIfNeeded(Activity activity) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
&& activity.checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, 42);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.farmerbb.taskbar.service.TaskbarService;
import com.farmerbb.taskbar.helper.GlobalHelper;
import com.farmerbb.taskbar.helper.FreeformHackHelper;
import com.farmerbb.taskbar.util.CompatUtils;
import com.farmerbb.taskbar.util.DependencyUtils;
import com.farmerbb.taskbar.helper.LauncherHelper;
import com.farmerbb.taskbar.util.U;
Expand Down Expand Up @@ -237,9 +238,10 @@ private void proceedWithAppLaunch(Bundle savedInstanceState) {
}

navigateTo(new ManageAppDataFragment());
} else if(!getIntent().hasExtra("theme_change"))
} else if(!getIntent().hasExtra("theme_change")) {
CompatUtils.grantNotificationPermissionIfNeeded(this);
navigateTo(new AboutFragment());
else
} else
navigateTo(new AppearanceFragment());
} else try {
Fragment oldFragment = getFragmentManager().findFragmentById(R.id.fragmentContainer);
Expand Down
1 change: 1 addition & 0 deletions app/src/playstore/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<uses-permission-sdk-23 android:name="android.permission.BLUETOOTH" />
<uses-permission-sdk-23 android:name="android.permission.QUERY_ALL_PACKAGES" />
<uses-permission-sdk-23 android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission-sdk-23 android:name="android.permission.POST_NOTIFICATIONS" />

<uses-permission-sdk-23 android:name="com.farmerbb.taskbar.support.USE_SUPPORT_LIBRARY" />

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {

dependencies {
classpath "com.android.tools.build:gradle:${AGP_VERSION}"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20'
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.5'
}
}
Expand Down

0 comments on commit 88aeca9

Please sign in to comment.