Skip to content

Commit

Permalink
show proper notification when alarm permission is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
newhinton committed Oct 18, 2023
1 parent 51e44c7 commit 44be076
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ class PermissionFragment : Fragment() {
mPermissionManager.requestStorage(this.requireActivity())
}
binding.buttonNotifications.setOnClickListener {
val settingsIntent: Intent = Intent(ACTION_APP_NOTIFICATION_SETTINGS)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(EXTRA_APP_PACKAGE, requireContext().packageName)
startActivity(settingsIntent)
startActivity(PermissionManager.getNotificationSettingsIntent(requireContext()))
}
}

Expand All @@ -62,7 +59,7 @@ class PermissionFragment : Fragment() {
if(mPermissionManager.grantedStorage() &&
mPermissionManager.grantedNotifications() &&
mPermissionManager.grantedStorage()) {
(requireActivity() as MainActivity).startRemotesFragment()
//(requireActivity() as MainActivity).startRemotesFragment()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ private void queueSingleScheduleTrigger(Trigger trigger){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean allowWhileIdle = sharedPreferences.getBoolean(context.getString(R.string.shared_preferences_allow_sync_trigger_while_idle), false);

Log.e("TAG", "1111");
if((new PermissionManager(context)).grantedAlarms()) {
Log.e("TAG", "granted");

if (allowWhileIdle) {
am.setExactAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
Expand All @@ -110,7 +107,6 @@ private void queueSingleScheduleTrigger(Trigger trigger){
);
}
} else {
Log.e("TAG", "not granted");
new AppErrorNotificationManager(context).showNotification();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ package ca.pkay.rcloneexplorer.notifications

import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.PendingIntent.FLAG_IMMUTABLE
import android.content.Context
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import ca.pkay.rcloneexplorer.R
import ca.pkay.rcloneexplorer.util.PermissionManager


class AppErrorNotificationManager(var mContext: Context) {

companion object {
private const val APP_ERROR_CHANNEL_ID =
"ca.pkay.rcloneexplorer.notifications.AppErrorNotificationManager"
private const val APP_ERROR_ID =
"ca.pkay.rcloneexplorer.notifications.AppErrorNotificationManager"
private const val APP_ERROR_ID = 51913
}

init {
Expand All @@ -36,24 +39,26 @@ class AppErrorNotificationManager(var mContext: Context) {
}

fun showNotification() {
val b = NotificationCompat.Builder(


/*val contentIntent = PendingIntent.getActivity(
mContext,
APP_ERROR_CHANNEL_ID
)
APP_ERROR_ID,
PermissionManager.getNotificationSettingsIntent(mContext), FLAG_IMMUTABLE
)*/

val b = NotificationCompat.Builder(mContext, APP_ERROR_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_twotone_error_24)
.setContentTitle("title")
.setContentText("content")
//.setContentIntent(pendingIntent)
//.setStyle(NotificationCompat.BigTextStyle().bigText(bigText.toString()))
//.addAction(
// R.drawable.ic_cancel_download,
// mContext.getString(R.string.cancel),
// cancelPendingIntent
//)
.setContentTitle(mContext.getString(R.string.app_error_notification_alarmpermission_missing))
.setContentText(mContext.getString(R.string.app_error_notification_alarmpermission_missing_description))
/*.addAction(
R.drawable.ic_cancel_download,
mContext.getString(R.string.cancel),
contentIntent
)*/
.setOnlyAlertOnce(true)
//.setProgress(100, percent, false)

val notificationManager = NotificationManagerCompat.from(mContext)
notificationManager.notify(1134, b.build())
notificationManager.notify(APP_ERROR_ID, b.build())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class PermissionManager(private var mContext: Context) {

companion object {
private const val REQ_ALL_FILES_ACCESS = 3101

fun getNotificationSettingsIntent(context: Context): Intent {
return Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
}
}

fun hasAllRequiredPermissions(): Boolean {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,6 @@
<string name="permissions_storage_label">Storage</string>
<string name="permissions_storage_description">This permission is required to access your local device. While you can still access remotes, it is highly recommended to allow access to your device.</string>
<string name="permissions_button_request">Request!</string>
<string name="app_error_notification_alarmpermission_missing">Alarm Scheduling Permission missing</string>
<string name="app_error_notification_alarmpermission_missing_description">Please grant this permission to allow schedules to be started. Without it, syncs wont run!</string>
</resources>

0 comments on commit 44be076

Please sign in to comment.