我正在 Delphi 10.2 上开发一个应用程序,我想使用来自 android webbrowser 的 php 打开它并向它发送一些数据。我有以下代码:
在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();
?>
德尔福:
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;
当我使用 php 访问 url 时,应用程序打开良好,但问题是在最后一个函数(函数 Frm.HandleIntentAction)中,valor 的值为 '' 而 valor3 为 nil。
知道发生了什么事吗?
非常感谢。
最佳答案
谢谢 mjn42。
解决方法是:
valor:=JStringToString(Data.getStringExtra(StringToJString('EXTRA_TEXT')));
现在可以了。
关于php - 使用 Intent 的 EXTRA_TEXT 中没有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48817462/