1

I'm developing an app on Delphi 10.2 and I want to open it using php from android webbrowser and send it some data. I have the following code:

Added in AndroidManifest.xml

    <intent-filter>  <!-- Introducimos estas líneas para que se pueda abrir la app desde el navegador -->
       <action android:name="android.intent.action.VIEW"/>
       <category android:name="android.intent.category.DEFAULT"/>
       <category android:name="android.intent.category.BROWSABLE"/>
       <data android:scheme="name" android:host="name" android:path="/"/>
       <data android:mimeType="text/plain"/> 
    </intent-filter> 

php:

<?php  
    include_once 'JString.php';
     $string = new JString("hola");
        header ("Location: intent://NAME/#Intent;scheme=NAME;component=com.APP.APP;type=text/plain;S.EXTRA_TEXT=$string;S.browser_fallback_url=http%3A%2F%2Furl.com;end"); 
        exit(); 
?>

Delphi:

    procedure frm.FormCreate(Sender: TObject);
    var
     AES: IFMXApplicationEventService;
    begin
     if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService,IInterface(AES)) then
        AES.SetApplicationEventHandler(onApplicationEvent);
      MainActivity.registerIntentAction(TJIntent.JavaClass.ACTION_VIEW);
      TMessageManager.DefaultManager.SubscribeToMessage(TMessageReceivedNotification, HandleActivityMessage);
    end;

    function frm.OnApplicationEvent(AAppEvent:TApplicationEvent;AContext:TObject):Boolean;
    var
    StartupIntent: JIntent;
      begin    
        case AAppEvent of
           TApplicationEvent.BecameActive:
           begin
            StartupIntent := MainActivity.getIntent;
            if StartupIntent <> nil then
              HandleIntentAction(StartupIntent);
           end;
        end;
        Result := False;
      end;

procedure Frm.HandleActivityMessage(const Sender: TObject; const M: TMessage);
begin
  if M is TMessageReceivedNotification then
    HandleIntentAction(TMessageReceivedNotification(M).Value);
end;

function Frm.HandleIntentAction(const Data: JIntent): Boolean;
var
  Extras: JBundle;
  valor,valor2:string;
  valor3:jstring;
begin
  valor:='nada';
  Result := False;
  if Data <> nil then
  begin
    Extras := Data.getExtras;
    if Extras <> nil then
    begin
     valor := JStringToString(Extras.getString(TJIntent.JavaClass.EXTRA_TEXT));
     valor3:= Extras.getString(TJIntent.JavaClass.EXTRA_TEXT);
    end;
    Invalidate;
  end;
  Label1.Text:=valor;
end;

When I go to the url with the php the app opens well but the problem is that in last function (function Frm.HandleIntentAction) the value of valor is '' and valor3 is nil.

Any idea about what is happening?

Thanks a lot.

Bazi
  • 37
  • 4
  • The Intent.EXTRA_TEXT constant has the value "android.intent.extra.TEXT" (see https://developer.android.com/reference/android/content/Intent.html#EXTRA_TEXT), so you are calling getString("android.intent.extra.TEXT"). To access your parameter, you must call getString("EXTRA_TEXT") – mjn42 Feb 16 '18 at 09:26
  • See https://stackoverflow.com/a/21304773/6517492 – mjn42 Feb 16 '18 at 09:27

1 Answers1

1

Thank you mjn42.

The solution is:

valor:=JStringToString(Data.getStringExtra(StringToJString('EXTRA_TEXT')));

Now it works.

Bazi
  • 37
  • 4