Jump to content
Sign in to follow this  
Piotr Daszewski

Delphi FMX Android - blocking push notifications permissions

Recommended Posts

Hello everyone.

How can I check in the Delphi (FMX) application for Android whether the push notifications permission has been received by the user in the system application settings?

NotificationCenter still sees the permission as granted.

A simple example:

procedure TMainForm.NotificationCenterPermissionRequestResult(Sender: TObject; const AIsGranted: Boolean);

begin

if AIsGranted then ShowMessage('IsGranted = True') else ShowMessage('IsGranted = False')

end;

procedure TMainForm.btnAuthorizationStatusClick(Sender: TObject);

begin

case NotificationCenter.AuthorizationStatus of

TAuthorizationStatus.NotDetermined: ShowMessage('AuthorizationStatus = NotDetermined');

TAuthorizationStatus.Restricted: ShowMessage('AuthorizationStatus = Restricted');

TAuthorizationStatus.Denied: ShowMessage('AuthorizationStatus = Denied');

TAuthorizationStatus.Authorized: ShowMessage('AuthorizationStatus = Authorized');

end;

end;

For procedures "NotificationCenterPermissionRequestResul" I always get "'IsGranted = True".

For the procedure "btnAuthorizationStatusClick" I always get "AuthorizationStatus = Authorized".

No way to identify that the user has turned off notifications.

Any suggestions? Hints?

I will be very grateful.

Share this post


Link to post
5 minutes ago, Piotr Daszewski said:

How can I check in the Delphi (FMX) application for Android whether the push notifications permission has been received by the user in the system application settings?

Modified code from the DW.FCMManager unit from this demo:

function IsPushEnabled(const AChannelId: string): Boolean;
var
  LService: JObject;
  LNotificationManager: JNotificationManager;
  LChannels: JList;
  LChannel: JNotificationChannel;
  I: Integer;
begin
  LService := TAndroidHelper.Context.getSystemService(TJContext.JavaClass.NOTIFICATION_SERVICE);
  LNotificationManager := TJNotificationManager.Wrap(TAndroidHelper.JObjectToID(LService));
  Result := LNotificationManager.areNotificationsEnabled;
  if Result and (TJBuild_Version.JavaClass.SDK_INT >= 26) then
  begin
    LChannels := LNotificationManager.getNotificationChannels;
    for I := 0 to LChannels.size - 1 do
    begin
      LChannel := TJNotificationChannel.Wrap(LChannels.get(I));
      if LChannel.getId.equals(StringToJString(AChannelId)) and (LChannel.getImportance = TJNotificationManager.JavaClass.IMPORTANCE_NONE) then
      begin
        Result := False;
        Break;
      end;
    end;
  end;
end;

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×