php - 使用 Intent 的 EXTRA_TEXT 中没有数据

标签 php android delphi android-intent

我正在 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/

相关文章:

php - 如果数据库为空,如何添加一条数据?

php - 在数组中查找总和等于给定数字的组合)元素总和

java - 发出声音的权限 - android studio api 高于 21

Android View淡出但不会淡入

delphi - 哪些积极开发的 Delphi 组件仍然支持 Kylix?

php - 从在 Woocommerce 中显示为列表的 SQL 查询获取订单

php - 如何通过索引获取 PHP DOMDocument 的子项

android - 安卓电子商务

multithreading - Delphi:Indy TIdTCPClient 读取数据

delphi - 如何更改 ScrollBar 的宽度?