Search code examples
delphifiremonkeydelphi-10.4-sydney

Delphi 10.4.2 FMX: How to write the case where the user press return button on android phone instead of choice in message dialog box?


    MessageDlg('Please turn on your gps', TMsgDlgType.mtConfirmation,
    [
      TMsgDlgBtn.mbYes,
      TMsgDlgBtn.mbNo,
      TMsgDlgBtn.mbClose
    ], 0,
    procedure(const AResult: TModalResult)
    begin
      case AResult of
        mrYES: begin
          LIntent := TJIntent.JavaClass.init(TJSettings.JavaClass.ACTION_LOCATION_SOURCE_SETTINGS);
          TAndroidHelper.Context.startActivity(LIntent);
        end;
        mrNo:
          Close;
        mrClose:
          Close;
        mrNone:
          Close;
      end;
    end);

Here are some code snippet I have been trying, I don't want to let the user proceed and close the app when the user click return button on the phone.


Solution

  • Thanks for everyone help. if-else case work.

        MessageDlg('Please turn on your gps', TMsgDlgType.mtConfirmation,
        [
          TMsgDlgBtn.mbYes,
          TMsgDlgBtn.mbNo
        ], 0,
        procedure(const AResult: TModalResult) begin
          if AResult = mrYES then begin
              LIntent := TJIntent.JavaClass.init(TJSettings.JavaClass.ACTION_LOCATION_SOURCE_SETTINGS);
              TAndroidHelper.Context.startActivity(LIntent);
          end
          else Close;
        end);