EXTRA_TEXT中没有使用intent的数据

时间:2018-02-15 22:38:45

标签: 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(); 
?>

的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;

当我使用php进入url时,应用程序打开很好,但问题是在最后一个函数(函数Frm.HandleIntentAction)中,valor的值是&#39;&#39;和valor3是零。

有关正在发生的事情的任何想法?

非常感谢。

1 个答案:

答案 0 :(得分:1)

谢谢mjn42。

解决方案是:

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

现在可行。