diff --git a/app/src/main/java/com/jens/automation2/ActivityPermissions.java b/app/src/main/java/com/jens/automation2/ActivityPermissions.java index 3530d668..76738cbe 100644 --- a/app/src/main/java/com/jens/automation2/ActivityPermissions.java +++ b/app/src/main/java/com/jens/automation2/ActivityPermissions.java @@ -3,6 +3,7 @@ package com.jens.automation2; import android.Manifest; import android.app.Activity; import android.app.AlertDialog; +import android.app.Notification; import android.app.NotificationManager; import android.content.ComponentName; import android.content.Context; @@ -21,6 +22,8 @@ import android.widget.Button; import android.widget.TextView; import android.widget.Toast; +import androidx.core.app.NotificationManagerCompat; + import com.jens.automation2.receivers.NotificationListener; import java.util.ArrayList; @@ -683,17 +686,14 @@ public class ActivityPermissions extends Activity case Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE: for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.notification)) usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); - break; case permissionNameGoogleActivityDetection: for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.activityDetection)) usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); - break; case Manifest.permission.ACTIVITY_RECOGNITION: for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.activityDetection)) usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); - break; case Manifest.permission.ACCESS_COARSE_LOCATION: // usingElements.add(getResources().getString(R.string.android_permission_ACCESS_COARSE_LOCATION)); @@ -1168,10 +1168,6 @@ public class ActivityPermissions extends Activity private void setHaveAllPermissions() { setResult(RESULT_OK); - // All permissions have been granted. - NotificationManager mNotificationManager = (NotificationManager) Miscellaneous.getAnyContext().getSystemService(Context.NOTIFICATION_SERVICE); - mNotificationManager.cancel(notificationIdPermissions); - ActivityMainScreen.updateMainScreen(); try { @@ -1182,6 +1178,14 @@ public class ActivityPermissions extends Activity // Activity may not have been loaded, yet. } + // All permissions have been granted. + NotificationManager mNotificationManager = (NotificationManager) Miscellaneous.getAnyContext().getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.cancel(notificationIdPermissions); + if(AutomationService.getInstance() != null) + AutomationService.getInstance().cancelNotification(); + + ActivityMainScreen.updateMainScreen(); + this.finish(); } diff --git a/app/src/main/java/com/jens/automation2/AutomationService.java b/app/src/main/java/com/jens/automation2/AutomationService.java index 4096d260..5c39d87c 100644 --- a/app/src/main/java/com/jens/automation2/AutomationService.java +++ b/app/src/main/java/com/jens/automation2/AutomationService.java @@ -24,6 +24,7 @@ import android.util.Log; import android.widget.Toast; import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; import com.jens.automation2.Trigger.Trigger_Enum; import com.jens.automation2.location.LocationProvider; @@ -407,6 +408,14 @@ public class AutomationService extends Service implements OnInitListener } } + public void cancelNotification() + { +// stopForeground(false); + NotificationManagerCompat.from(AutomationService.this).cancelAll(); +// NotificationManagerCompat.from(AutomationService.this).cancel(ActivityPermissions.notificationIdPermissions); +// NotificationManagerCompat.from(AutomationService.this).cancel(AutomationService.notificationIdRestrictions); + } + protected void checkForMissingBackgroundLocationPermission() { if(Miscellaneous.googleToBlameForLocation(true)) @@ -421,23 +430,6 @@ public class AutomationService extends Service implements OnInitListener else Miscellaneous.createDismissableNotification(getResources().getString(R.string.featuresDisabled), notificationIdLocationRestriction, pi); } - - /* - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) - { - if (BuildConfig.FLAVOR.equalsIgnoreCase("googlePlayFlavor")) - { - if (Rule.isAnyRuleUsing(Trigger_Enum.pointOfInterest)) - { - Intent intent = new Intent(AutomationService.this, ActivityMainTabLayout.class); - PendingIntent pi = PendingIntent.getActivity(AutomationService.this, 0, intent, 0); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) - Miscellaneous.createDismissableNotificationWithDelay(2200, getResources().getString(R.string.featuresDisabled), notificationIdLocationRestriction, pi); - else - Miscellaneous.createDismissableNotification(getResources().getString(R.string.featuresDisabled), notificationIdLocationRestriction, pi); - } - } - }*/ } public static void startAutomationService(Context context, boolean startAtBoot) diff --git a/app/src/main/java/com/jens/automation2/Miscellaneous.java b/app/src/main/java/com/jens/automation2/Miscellaneous.java index e077ab5a..bae4a4c8 100644 --- a/app/src/main/java/com/jens/automation2/Miscellaneous.java +++ b/app/src/main/java/com/jens/automation2/Miscellaneous.java @@ -911,6 +911,7 @@ public class Miscellaneous extends Service dismissableNotificationBuilder.setContentText(textToDisplay); dismissableNotificationBuilder.setContentIntent(pendingIntent); dismissableNotificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(textToDisplay)); + dismissableNotificationBuilder.setAutoCancel(true); Notification dismissableNotification = dismissableNotificationBuilder.build(); @@ -1012,6 +1013,7 @@ public class Miscellaneous extends Service if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) builder.setCategory(Notification.CATEGORY_SERVICE); + builder.setAutoCancel(true); builder.setWhen(System.currentTimeMillis()); builder.setContentIntent(myPendingIntent);