Sending Android Intents from Delphi (Part 1)

Posted on gio 26 settembre 2013 in Android, Delphi XE5

As you probably know, I work for the italian embarcadero representative (, so last week, I've been in Milan (Italy) with the Delphi Product Manager Marco Cantù, to show the new Delphi XE5 for Android (and iOS...).

Users (old and new) were enthusiastics. The Delphi-WAY combined with the Android openness and flexibility, is really a good way to develop mobile apps for the business customers.

So, after the initial demos some users were interested in sending Android Intents from their Delphi app.

I've builded some demos about Intents, so I showed those demos to them (in the next weeks there will be many Delphi for Android training in Italy, so I've build those demo in advance)

In Delphi XE5 you can call java classes from the Google SDK. So I started investigating hot to do this.

There are a lot of possibilities, and I'm still doing research, but this is a simple Intent send demos.


This is the code under the first button.

``` {lang="delphi"} procedure THeaderFooterForm.Button1Click(Sender: TObject); var Intent: JIntent; begin // JAVA SDK ANDROID HELP SAYS... // String url = ""; // Intent i = new Intent(Intent.ACTION_VIEW); // i.setData(Uri.parse(url)); // startActivity(i);

Intent := TJIntent.Create; Intent.setAction(TJIntent.JavaClass.ACTION_VIEW); Intent.setData(TJnet_Uri.JavaClass.parse (StringToJString(''))); MainActivity.startActivity(Intent); end;

Simple, isn't it?

With this piece of code, you cann open your device browser to a web site (my blog in the snippet).

Click on the first button and you will be redirected to this blog.



[Intents are REALLY powerfull]{style="font-size: 13px;"}

With the next snippet, you can send piece of data (e.g. text) to other apps. You dont have to know the apps in advance, Android will do the match with the Implicit Intent. (It is similat to the TShowShareSheet action).

``` {lang="delphi"}
procedure THeaderFooterForm.Button2Click(Sender: TObject);
  Intent: JIntent;
  // Intent intent = new Intent(Intent.ACTION_SEND);
  // intent.setType("text/plain");
  // intent.putExtra(android.content.Intent.EXTRA_TEXT, "Android Rocks!!!");
  // startActivity(intent);

  Intent := TJIntent.Create;
    StringToJString('Delphi Rocks!!!'));


Now, if you choose Twitter, you will get this screen.


I've demos about placing a call, sending an SMS, show a PDF file, accessing different kind of storage etc.\ In the next part of this mini series I'll show some other snippets.

There is still many areas to explore...

  • [Services]{style="font-size: 13px;"}
  • [BroadcastReceiver]{style="font-size: 13px;"}
  • [Widget]{style="font-size: 13px;"}
  • [Bluetooth]{style="font-size: 13px;"}
  • [I/O]{style="font-size: 13px;"}
  • [...?]{style="font-size: 13px;"}

I'll keep you informed...