Jump to content

Dave Nottage

Members
  • Content Count

    1337
  • Joined

  • Last visited

  • Days Won

    29

Posts posted by Dave Nottage


  1. 2 minutes ago, quini said:

    Is it possible to generate an Android App Bundle file (necessary to submitt the ANDROID project to Google playstore) using RAD Studio 10.2 Tokyo?

    Not "out of the box" - it might be possible using a whole bunch of command line commands, however if you're serious about having something on Google Play, you're far better off upgrading. You could start with Delphi 10.4 Community Edition, depending on what you earn.


  2. 7 hours ago, stacker_liew said:

    Finally, I changed the package in Version Info to something else other than the original com.embarcadero., it managed to install the app

    Uninstalling the original app would have had the same effect.

    8 hours ago, stacker_liew said:

    I added android:exported="true" to AndroidMainfest.template

    If you find you need to add that attribute, please refer to: 

     

    • Thanks 1

  3. 5 minutes ago, programmerdelphi2k said:

    sorry about your "nothing yet right"

    This is a forum for solving problems for other developers. Your answer does not solve the question that was asked. Posting wrong answers only serves to confuse developers that might come across them

    • Like 3

  4. 4 minutes ago, programmerdelphi2k said:

    I have used this code in my project and for works

    Yet another wrong answer. This code only compares what the current mode currently is, with auto (which is not one of the continuous modes)  - it does not compensate for what modes are supported


  5. 19 minutes ago, KMarb said:

    It seems that some models of phone (or some front cameras) +might not allow me to set focusMode at all... is that correct?

    Most front cameras support fixed (TFocusMode.Locked) only. One way (likely the easiest) to resolve this would be to use a patched FMX.Media.Android unit. Copy the unit to the project folder and change this routine:

    procedure TAndroidVideoCaptureDevice.SetFocusMode(const AFocusMode: TFocusMode);
    var
      Params: JCamera_Parameters;
      // Patch code vars:
      LFocusModes: JList;
      LFocusMode: JString;
      I: Integer;
      LIsSupported: Boolean;
    begin
      Params := Camera.getParameters;
      if Params = nil then
        Exit;
    
      // Patch code BEGIN
      LIsSupported := False;
      LFocusModes := Params.getSupportedFocusModes;
      for I := 0 to LFocusModes.size - 1 do
      begin
        LFocusMode := TJString.Wrap(LFocusModes.get(I));
        if ((AFocusMode = TFocusMode.AutoFocus) and LFocusMode.equals(TJCamera_Parameters.JavaClass.FOCUS_MODE_AUTO)) or
          ((AFocusMode = TFocusMode.Locked) and LFocusMode.equals(TJCamera_Parameters.JavaClass.FOCUS_MODE_FIXED)) or
          ((AFocusMode = TFocusMode.ContinuousAutoFocus) and LFocusMode.equals(TJCamera_Parameters.JavaClass.FOCUS_MODE_CONTINUOUS_PICTURE)) then
        begin
          LIsSupported := True;
          Break;
        end;
      end;
      if not LIsSupported then
        Exit;
      // Patch code END
    
      FFocusMode.Value := AFocusMode;
    
      UpdateFocusModeParameter(Params);
      Camera.setParameters(Params);
    
      SetAutoFocus;
    end;

    This means that if the mode is not supported, it doesn't try and change it, so it will remain either the default, or the last supported mode it was set to.


  6. 2 hours ago, CoeurdeLeon said:

    Function ChatWithGPT(Const question, Api_Key: String): String;
    Function ChatWithGPT3(Const question, Api_Key: String): String;

    image.png.043e70d14fb302e188c25f8fc8cac327.png

    Because the URL is probably invalid. It does not appear to be documented anywhere.

    2 hours ago, CoeurdeLeon said:

    Function ChatWithGPT2(Const question, Api_Key: String): String;

    image.png.046f7ce9dc8aa36e7d761c16b06435ee.png

    Because, as the error says, the request is bad. As I said:

    2 hours ago, Dave Nottage said:

    Do the quotes here really need to be escaped?

    This should work as long as there's no characters that need escaping in the question variable:

    rest.PostData     :=
          '{"model": "text-davinci-003", "prompt": "' + question + '", "temperature": 0, "max_tokens": 64}';

     


  7. 2 hours ago, CoeurdeLeon said:

    I get a variety of errors

    Why did you choose not to include those in your post?

    2 hours ago, CoeurdeLeon said:

        rest.PostData     :=
          '{\"model\": \"text-davinci-003\", \"prompt\": \"" + question + "\", \"temperature\": 0, \"max_tokens\": 64}';

    Do the quotes here really need to be escaped?

    2 hours ago, CoeurdeLeon said:

    http.Get('https://api.openai.com/v1/chatgpt/chat?question=' + question);

    Is that URL documented somewhere? I'm unable to find it

    • Like 1

  8. 5 hours ago, John van de Waeter said:

    The Android PermissionsService from System.Permissions seems to lack a permission for push-notifications, which is needed (afaik) for Android 13 and up

    Yes, you will need to manually add the permission to the manifest - one way is to modify AndroidManifest.template.xml to add:

        <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

    A suitable location would be just below <%uses-permission%>
     

    You will also need to request the permission in your code, e.g:

      PermissionsService.RequestPermissions(['android.permission.POST_NOTIFICATIONS'],
        procedure(const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray)
        begin
          if AGrantResults[0] = TPermissionStatus.Granted then
            // Permission was granted
        end
      );

     

    • Like 1

  9. This could be one way:

    unit Unit1;
    
    interface
    
    uses
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.WebBrowser, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit,
      Androidapi.JNIBridge, Androidapi.JNI.WebKit, Androidapi.JNI.JavaTypes;
    
    type
      TJavaScriptResultEvent = procedure(Sender: TObject; const JavaScriptResult: string) of object;
    
      TJavaScriptValueCallback = class(TJavaLocal, JValueCallback)
      private
        FOnResult: TJavaScriptResultEvent;
      public
        { JValueCallback }
        procedure onReceiveValue(value: JObject); cdecl;
      public
        property OnResult: TJavaScriptResultEvent read FOnResult write FOnResult;
      end;
    
      TForm1 = class(TForm)
        WebBrowser: TWebBrowser;
        Button1: TButton;
        Edit1: TEdit;
        procedure Button1Click(Sender: TObject);
      private
        FJavaScriptValueCallback: TJavaScriptValueCallback;
        procedure NewDateResultHandler(Sender: TObject; const AJavaScriptResult: string);
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.fmx}
    
    uses
      Androidapi.Helpers;
    
    { TJavaScriptValueCallback }
    
    procedure TJavaScriptValueCallback.onReceiveValue(value: JObject);
    begin
      if Assigned(FOnResult) then
        FOnResult(Self, JStringToString(TJString.Wrap(value)).DeQuotedString('"'));
    end;
    
    { TForm1 }
    
    constructor TForm1.Create(AOwner: TComponent);
    begin
      inherited;
      FJavaScriptValueCallback := TJavaScriptValueCallback.Create;
    end;
    
    destructor TForm1.Destroy;
    begin
      FJavaScriptValueCallback.Free;
      inherited;
    end;
    
    procedure TForm1.NewDateResultHandler(Sender: TObject; const AJavaScriptResult: string);
    begin
      Edit1.Text := AJavaScriptResult;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      LWebView: JWebView;
    begin
      if Supports(WebBrowser, JWebView, LWebView) then
      begin
        FJavaScriptValueCallback.OnResult := NewDateResultHandler;
        LWebView.evaluateJavascript(StringToJString('new Date()'), FJavaScriptValueCallback);
      end;
    end;
    
    end.

     


  10. 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

  11. Your intent-filter node is missing from the manifest. The activity node should look like this:

            <activity
                android:name="com.embarcadero.firemonkey.FMXNativeActivity"
                android:label="MixPDV"
                android:exported = "true"
                android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
                android:launchMode="singleTask">
                <!-- Tell NativeActivity the name of our .so -->
                <meta-data android:name="android.app.lib_name" android:value="MixPDV" />
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>

     

    • Thanks 1

  12. 4 minutes ago, Abraão said:

    it installs, but the icon does not appear on the desktop of the cell phone and the "Open" button does not appear in the Play Store

    Did you set the option to generate 32-bit and 64-bit binaries in the Project Options?

     

    image.thumb.png.3f813823b9d2b47082127ea3308d02ab.png

×