Jump to content
Registration disabled at the moment Read more... ×
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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×