-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/add-notification-permission' int…
…o #583-Release-Middleware1.3.66
- Loading branch information
Showing
16 changed files
with
722 additions
and
425 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/fiskaltrust.AndroidLauncher.Common/Activitites/IntroductionActivity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using Android.App; | ||
using Android.Content; | ||
using Android.OS; | ||
using Android.Runtime; | ||
using Android.Views; | ||
using Android.Widget; | ||
using fiskaltrust.AndroidLauncher.Common.Constants; | ||
using fiskaltrust.AndroidLauncher.Common.Helpers; | ||
using Java.Interop; | ||
using Microsoft.Extensions.Primitives; | ||
using System.Linq; | ||
using System.Threading; | ||
|
||
namespace fiskaltrust.AndroidLauncher.Common.Activitites | ||
{ | ||
[Activity(Label = "IntroductionActivity", Name = "eu.fiskaltrust.androidlauncher.common.IntroductionActivity", Exported = true)] | ||
public class IntroductionActivity : Activity | ||
{ | ||
private Bundle? _startIntent; | ||
private string? _startIntentName; | ||
|
||
protected override void OnCreate(Bundle savedInstanceState) | ||
{ | ||
base.OnCreate(savedInstanceState); | ||
SetContentView(Resource.Layout.activity_introduction); | ||
|
||
FindViewById<Button>(Resource.Id.buttonRequestNotification).Enabled = !NotificationPermissionHelper.IsAllowingNotifications(this); | ||
|
||
FindViewById<Button>(Resource.Id.buttonRequestBatteryOptimization).Enabled = !PowerManagerHelper.IsIgnoringBatteryOptimizations(this); | ||
if (Intent.HasExtra("StartIntent")) | ||
{ | ||
_startIntent = Intent.GetBundleExtra("StartIntent"); | ||
_startIntentName = Intent.GetStringExtra("StartIntentName"); | ||
} | ||
} | ||
|
||
[Export("buttonRequestNotificationOnCLick")] | ||
public void ButtonRequestNotificationOnCLick(View v) | ||
{ | ||
NotificationPermissionHelper.AskUserToAllowNotifications(this, 2); | ||
|
||
} | ||
|
||
[Export("buttonRequestBatteryOptimizationOnCLick")] | ||
public void ButtonRequestBatteryOptimizationOnCLick(View v) | ||
{ | ||
PowerManagerHelper.AskUserToDisableBatteryOptimization(this); | ||
FindViewById<Button>(Resource.Id.buttonRequestBatteryOptimization).Enabled = !PowerManagerHelper.IsIgnoringBatteryOptimizations(this); | ||
} | ||
|
||
protected override void OnResume() | ||
{ | ||
base.OnResume(); | ||
FindViewById<Button>(Resource.Id.buttonRequestBatteryOptimization).Enabled = !PowerManagerHelper.IsIgnoringBatteryOptimizations(this); | ||
FindViewById<Button>(Resource.Id.buttonRequestNotification).Enabled = !NotificationPermissionHelper.IsAllowingNotifications(this); | ||
|
||
TryContinue(); | ||
} | ||
|
||
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) | ||
{ | ||
base.OnActivityResult(requestCode, resultCode, data); | ||
if (resultCode == Result.Ok) | ||
{ | ||
if (requestCode == 2) | ||
{ | ||
FindViewById<Button>(Resource.Id.buttonRequestNotification).Enabled = !NotificationPermissionHelper.IsAllowingNotifications(this); | ||
} | ||
TryContinue(); | ||
} | ||
} | ||
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults) | ||
{ | ||
base.OnRequestPermissionsResult(requestCode, permissions, grantResults); | ||
if (grantResults[0] == Android.Content.PM.Permission.Denied) | ||
{ | ||
FindViewById<Button>(Resource.Id.buttonRequestNotification).Enabled = !NotificationPermissionHelper.IsAllowingNotifications(this); | ||
TryContinue(); | ||
} | ||
} | ||
|
||
|
||
private void TryContinue() | ||
{ | ||
if ( | ||
PowerManagerHelper.IsIgnoringBatteryOptimizations(this) | ||
&& | ||
NotificationPermissionHelper.IsAllowingNotifications(this) | ||
) | ||
{ | ||
if (_startIntent is not null) | ||
{ | ||
var startIntent = new Intent(Intent.ActionSend); | ||
startIntent.SetComponent(new ComponentName(PackageName, _startIntentName)); | ||
startIntent.PutExtras(_startIntent); | ||
SendBroadcast(startIntent); | ||
} | ||
|
||
SetResult(0); | ||
Finish(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/fiskaltrust.AndroidLauncher.Common/Helpers/NotificationPermissionHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Android.App; | ||
using Android.Content; | ||
using Android.Content.PM; | ||
using Android.OS; | ||
using Android.Support.V4.Content; | ||
using Android.Support.V7.App; | ||
using System; | ||
|
||
namespace fiskaltrust.AndroidLauncher.Common.Helpers | ||
{ | ||
public static class NotificationPermissionHelper | ||
{ | ||
public static void AskUserToAllowNotifications(Activity activity, int requestCode) | ||
{ | ||
if (!IsAllowingNotifications(activity.ApplicationContext)) | ||
{ | ||
activity.RequestPermissions(new[]{Android.Manifest.Permission.PostNotifications}, requestCode); | ||
} | ||
} | ||
|
||
public static bool IsAllowingNotifications(Context context) | ||
{ | ||
return context.CheckSelfPermission(Android.Manifest.Permission.PostNotifications) == Permission.Granted; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.