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.