permission for play sound

This commit is contained in:
jens 2021-11-03 15:15:06 +01:00
parent 9a6083247f
commit 23502f52bb
3 changed files with 22 additions and 24 deletions

View File

@ -3,6 +3,7 @@ package com.jens.automation2;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
@ -21,6 +22,8 @@ import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.core.app.NotificationManagerCompat;
import com.jens.automation2.receivers.NotificationListener; import com.jens.automation2.receivers.NotificationListener;
import java.util.ArrayList; import java.util.ArrayList;
@ -683,17 +686,14 @@ public class ActivityPermissions extends Activity
case Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE: case Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE:
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.notification)) for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.notification))
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
break; break;
case permissionNameGoogleActivityDetection: case permissionNameGoogleActivityDetection:
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.activityDetection)) for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.activityDetection))
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
break; break;
case Manifest.permission.ACTIVITY_RECOGNITION: case Manifest.permission.ACTIVITY_RECOGNITION:
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.activityDetection)) for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.activityDetection))
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
break; break;
case Manifest.permission.ACCESS_COARSE_LOCATION: case Manifest.permission.ACCESS_COARSE_LOCATION:
// usingElements.add(getResources().getString(R.string.android_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() private void setHaveAllPermissions()
{ {
setResult(RESULT_OK); setResult(RESULT_OK);
// All permissions have been granted.
NotificationManager mNotificationManager = (NotificationManager) Miscellaneous.getAnyContext().getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(notificationIdPermissions);
ActivityMainScreen.updateMainScreen();
try try
{ {
@ -1182,6 +1178,14 @@ public class ActivityPermissions extends Activity
// Activity may not have been loaded, yet. // 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(); this.finish();
} }

View File

@ -24,6 +24,7 @@ import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import com.jens.automation2.Trigger.Trigger_Enum; import com.jens.automation2.Trigger.Trigger_Enum;
import com.jens.automation2.location.LocationProvider; 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() protected void checkForMissingBackgroundLocationPermission()
{ {
if(Miscellaneous.googleToBlameForLocation(true)) if(Miscellaneous.googleToBlameForLocation(true))
@ -421,23 +430,6 @@ public class AutomationService extends Service implements OnInitListener
else else
Miscellaneous.createDismissableNotification(getResources().getString(R.string.featuresDisabled), notificationIdLocationRestriction, pi); 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) public static void startAutomationService(Context context, boolean startAtBoot)

View File

@ -911,6 +911,7 @@ public class Miscellaneous extends Service
dismissableNotificationBuilder.setContentText(textToDisplay); dismissableNotificationBuilder.setContentText(textToDisplay);
dismissableNotificationBuilder.setContentIntent(pendingIntent); dismissableNotificationBuilder.setContentIntent(pendingIntent);
dismissableNotificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(textToDisplay)); dismissableNotificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(textToDisplay));
dismissableNotificationBuilder.setAutoCancel(true);
Notification dismissableNotification = dismissableNotificationBuilder.build(); Notification dismissableNotification = dismissableNotificationBuilder.build();
@ -1012,6 +1013,7 @@ public class Miscellaneous extends Service
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
builder.setCategory(Notification.CATEGORY_SERVICE); builder.setCategory(Notification.CATEGORY_SERVICE);
builder.setAutoCancel(true);
builder.setWhen(System.currentTimeMillis()); builder.setWhen(System.currentTimeMillis());
builder.setContentIntent(myPendingIntent); builder.setContentIntent(myPendingIntent);