Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the issue that location permission notification cannot be removed #2465

Closed
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,13 @@ class AskPermissionNotificationActivity : AppCompatActivity() {
companion object {
private const val SHARED_PREFERENCE_NAME = "location_perm_notify"
const val PERMISSION_REJECT_SHOW = "permission_reject_show"
private const val PERMISSION_IS_SHOW = "permission_is_show"
private const val NOTIFICATION_ID = 1026359765

private var notificationIsShown = false

@JvmStatic
fun showLocationPermissionNotification(context: Context) {
val sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCE_NAME, MODE_PRIVATE)
val notificationIsShown = sharedPreferences.getBoolean(PERMISSION_IS_SHOW, false)
if (notificationIsShown) return
AskPermissionNotificationCancel.register(context)
val appName = context.packageManager.getApplicationLabel(context.packageName).toString()
Expand All @@ -239,15 +240,17 @@ class AskPermissionNotificationActivity : AppCompatActivity() {
.setDeleteIntent(PendingIntent.getBroadcast(context, 0, AskPermissionNotificationCancel.getTrigger(context), FLAG_IMMUTABLE))
.build()
context.getSystemService<NotificationManager>()?.notify(NOTIFICATION_ID, notification)
notificationIsShown = true
sharedPreferences.edit().putBoolean(PERMISSION_IS_SHOW, true).apply()
}

@JvmStatic
fun hideLocationPermissionNotification(context: Context) {
val sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCE_NAME, MODE_PRIVATE)
val notificationIsShown = sharedPreferences.getBoolean(PERMISSION_IS_SHOW, false)
if (!notificationIsShown) return
context.getSystemService<NotificationManager>()?.cancel(NOTIFICATION_ID)
AskPermissionNotificationCancel.unregister(context)
notificationIsShown = false
sharedPreferences.edit().putBoolean(PERMISSION_IS_SHOW, false).apply()
}

@TargetApi(26)
Expand Down