Jump to content
Massimiliano S

FMX.Android Intents Sample missing procedure

Recommended Posts

I'm looking at this example because my app stops when it receives an intent if the app is already running

https://github.com/Embarcadero/RADStudio10.4Demos/tree/master/Object%20Pascal/Mobile%20Snippets/AndroidIntents

 

The example says:

ReceiveIntent

ReceiveIntent project has one source file, Unit1.pas. It receives and shows the text from the SendIntent application.

  • HandleIntentAction function verifies that the intent contains information and shows the text on the TMemo1.

  • HandleAppEvent function verifies that the intent is not null and calls HandleIntentAction function with the received itent. This function handles the intent the first time ReceiveIntent opens.

  • ReceiveIntent procedure handles the intent when ReceiveIntent is already open. The itent is register using MainActivity.registerIntentAction(TJIntent.JavaClass.ACTION_VIEW);.To receive simple data from other applications, you need to update the Android Manifest file to create the intent filters that are necessary to receive intents for a specific action. After editing the Android Manifest for a specific action, when SendIntent application tries to share the information passing the intent to startActivity(), ReceiveIntent appears as the option to view this information. If more than one options is available, an app chooser with all the apps appears.

 

 

Unfortunately I don't see this procedure ReceiveIntent

do you know how to handle this situation?

Thanks

Max

 

Share this post


Link to post

Not sure what the question really is.

procedure TForm1.FormCreate(Sender: TObject);
var
  AppEventService: IFMXApplicationEventService;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, AppEventService) then
    AppEventService.SetApplicationEventHandler(HandleAppEvent);

  // Register the type of intent action that we want to be able to receive.
  // Note: A corresponding <action> tag must also exist in the <intent-filter> section of AndroidManifest.template.xml.
  MainActivity.registerIntentAction(TJIntent.JavaClass.ACTION_VIEW);
  TMessageManager.DefaultManager.SubscribeToMessage(TMessageReceivedNotification, HandleActivityMessage);
end;

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

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

function TForm1.HandleIntentAction(const Data: JIntent): Boolean;
var
  Extras: JBundle;
begin
  Result := False;
  if Data <> nil then
  begin
    Memo1.ClearContent;
    Extras := Data.getExtras;
    if Extras <> nil then
      Memo1.Text := JStringToString(Extras.getString(TJIntent.JavaClass.EXTRA_TEXT));
    Invalidate;
  end;
end;

HandleIntentAction(const Data: JIntent): Boolean;

Is the Action function that is doing the work when the intent is proceeded.

 

While

TMessageManager.DefaultManager.SubscribeToMessage(TMessageReceivedNotification, HandleActivityMessage);

registers the Handler.

 

and this can be called from two sides,
1. from the handler:    HandleIntentAction(TMessageReceivedNotification(M).Value);

    By the registered callback

.

2. StartupIntent := MainActivity.getIntent;
    if StartupIntent <> nil then
      HandleIntentAction(StartupIntent);

   During startup of the app: when the OS puts the app into foreground by selecting the intent.

 

Just looked fastly over this, what exactly is missing ?

 

 

 

Edited by Rollo62

Share this post


Link to post

Hello,
Thanks a lot for the answer
The problem is that I have changed my manifest from

 

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:mimeType="text/pas" />
            </intent-filter> 

 

to

 

<intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT"/> 
                <data android:mimeType="application/*" />
                <data android:mimeType="message/*" />
                <data android:mimeType="multipart/*" />
                <data android:mimeType="text/*" />
            </intent-filter>

 

In order to have the ability to receive shared links from chrome


When the app is closed everything works and after the first share app is launched, but when the app is already open Chrome opens a second  instance internally and the app hangs on the splash until I close the already open app

Using  this example I have the same problem Like my app, when the app is already open the intent is not managed and the app remains blocked

 

Kind regards

Max

Share this post


Link to post
5 hours ago, Rollo62 said:

Have you checked out the Kastri project ?

Not sure that there's anything in it to solve his issue, but thanks for the plug 🙂

6 hours ago, Massimiliano S said:

Using  this example I have the same problem Like my app, when the app is already open the intent is not managed and the app remains blocked

I have a feeling it's a simple entry in the manifest. Added to my already huge to-do list.

Share this post


Link to post

@Dave Nottage

Yes, no direct solution.

But maybe the intent filter could lead to some insights, howto achieve that goal in Java and Delphi.

Share this post


Link to post

Thank you,

unfortunately it does not solve the problem.

The problem would seem to be related to the fact that Chrome opens the app internally within a custom tab, but it is a hypothesis
If I use other browsers such as Dolphin, the intent is managed whether the app is closed or already open.

On the other hand, if Chrome finds the app open, it still launches a second instance internally which, however, remains blocked on the splash form until I close the first app
I have seen that Chrome also behaves like this with all the other apps (gmail, whats app etc ..) which, however, are still able to manage the call
I tried to modify the manifest, the launchmode but I can't prevent this or manage the double execution anyway.
I am now working on a test app and then port the change to mine which uses the same principle, but this issue is blocking for release
I tried to declare a second activity  different from main but I didn't find how to register the action. It is seen by chrome in shared panel but it is not launched.

here i found some configurations to put in the manifest but nothing seems to work
https://developer.android.com/guide/topics/manifest/activity-element#embedded


I thought about trying with the remote services but I don't know if a service can manage the share from chrome and if it solves the problem. Or are there other possibilities?
I enclose the project if it can be clearer where I am going to save all the steps that are made in a text file.

Thank you very much for your availability

ReceiveIntent.zip

Share this post


Link to post
On 7/8/2020 at 23:46, Dave Nottage said:

Non sono sicuro che ci sia qualcosa per risolvere il suo problema, ma grazie per il plug 🙂

Ho la sensazione che sia una semplice voce nel manifesto. Aggiunto alla mia già vasta lista di cose da fare.

Hi Dave,

Do you have any hints and tips on what to look for?
I'm stuck and on the various other forums (also Idera/Emarcadero) I'm not getting any response,
eternally grateful

MAx

Share this post


Link to post
5 hours ago, Massimiliano S said:

Hi Dave,

Do you have any hints and tips on what to look for?

No idea at this point, sorry. As I say, it's on my list.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×