Sending Android Intents from Delphi (Part 2)

Some months ago I wrote a post with title “Sending Android Intents from Delphi (Part 1)”. In that post I promised to write a 2nd part… here’s it is!

This time I want to play a video deployed with my APK using an external player.

Some informations are available on the Internet, but to correctly know how to play the video I’ve to inspect my Nexus 5 with the LogCat while using the default file manager to start the default video player.

The app main form  is shown below

The main form
The main form

 

I’ve added an mp4 video file using the deployment manager.

This is the code under the button click event

procedure TForm1.Button1Click(Sender: TObject);
var
  Intent: JIntent;
  FileName, DestFileName: string;
  Data: Jnet_Uri;
  CompName: JComponentName;
const
  VIDEO_FILENAME = 'videoviewdemo.mp4';
begin
  FileName := System.IOUtils.TPath.GetDocumentsPath + PathDelim + VIDEO_FILENAME;
  DestFileName := TPath.GetSharedDownloadsPath + PathDelim + VIDEO_FILENAME;
  // Copy the file into a public path (you can use any public path)
  TFile.Copy(FileName, DestFileName, true);
  Data := TJnet_Uri.JavaClass.parse(StringToJString('file://' + DestFileName));
  Intent := TJIntent.Create;
  Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
  if CheckBox1.IsChecked then
  begin
    CompName := TJComponentName.JavaClass.init(StringToJString('android'),
      StringToJString('com.android.internal.app.ResolverActivity'));
    Intent.setComponent(CompName);
  end;
  Intent.setDataAndType(Data, StringToJString('video/mp4'));
  try
    MainActivity.startActivity(Intent);
  except
    on E: Exception do
    begin
      Label1.Text := E.Message;
    end;
  end;
end;

Using the checkbox you can force the OS to show the ResolverActivity.

see you

Sending Android Intents from Delphi (Part 1)

As you probably know, I work for the italian embarcadero representative (www.bittime.it), 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.

The Intents demo app
The Intents demo app

 

This is the code under the first button.

procedure THeaderFooterForm.Button1Click(Sender: TObject);
var
  Intent: JIntent;
begin
  // JAVA SDK ANDROID HELP SAYS...
  // String url = "http://www.example.com";
  // 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('http://www.danieleteti.it')));
  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.

Open browser with intent
Open browser with intent

 

Intents are REALLY powerfull

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).

procedure THeaderFooterForm.Button2Click(Sender: TObject);
var
  Intent: JIntent;
begin
  // 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;
  Intent.setType(StringToJString('text/plain'));
  Intent.setAction(TJIntent.JavaClass.ACTION_SEND);
  Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT,
    StringToJString('Delphi Rocks!!!'));
  MainActivity.startActivity(Intent);
end;
Chose wich apps shoud be launched to handle the intent (and the text)
Chose wich apps shoud be launched to handle the intent (and the text)

 

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

Intent handle by twitter app
Intent handle by twitter app

 

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
  • BroadcastReceiver
  • Widget
  • Bluetooth
  • I/O
  • …?

I’ll keep you informed…

DROIDDevCon – Call4Papers

DROIDDevCon is the first conference in italy completly focused on Android OS development.

This post is the official opening for the call4papers!

Dear potential DROIDDevCon speaker,

I’m building the agenda for first DROIDDevCon that will be held October 24th in Verona (Italy).

The call for papers are officially open right now, so if you want to propose some speeches, I’ll be glad to see it.

As usual, for the Call4Paper I need:

  • Title (for every talk)
  • Abstract (for every talk)
  • Difficulty level (for every talk. Difficulty level is a scale from 1 to 3 with the following mean: introduction, intermediate, advanced)
  • Speaker’s photo
  • Speaker’s profile

I’m looking forward to your proposal. The call4papers ends at July 31st, 2012.

Send your proposal to call4paper(at)droiddevcon.it.

Proposals will be evaluated and the speakers will be contacted ASAP.

This year topics will be the following:

TOPICS

  • What’s New in Android >= ICS
  • Android Fundamentals
  • Android Core
  • Android Tablets development
  • Android Phone developments
  • OpenSource Frameworks
  • Android and MOMs
  • Android clients for REST or SOAP services
  • Game development & game engines
  • The Android Open Accessory Development Kit (ADK)
  • Backward Compatibility
  • Mobile cross platform development
  • TDD for Android
  • Continuous Integration
  • Testing
  • Android UI Design Patterns
  • Android Best Practices
  • Performance Best Practices
  • NFC
  • NDK (Native Development Kit)
  • Location and Maps
  • HTML5/SVG/WebGL and Android
  • OOD/OOP
  • Metaprogramming
  • Games
  • SOA/ROA
  • Architectures

Target audience

  • Software architects
  • Software developers
  • Project managers
  • IT managers
  • Trainers

The conference web site is http://www.droiddevcon.it.

Are you interested in a specific topic? What do you suggest for DROIDDevCon2012? Let me know

Thanks and see you at DROIDDevCon 2012.

Would you like to partecipate in a conference completely focused on Android development? Come to the DROIDDevCon!

Do you wanna see an enormous potential tool? Here’s the pascal for Java and Android

Yes, this is very cool. I’m not a Java hater, in terms of language (and I dont want to start a language-war), but some Java features, IMHO, are a bit uncomfortable for me.
However, Java is very powerful and there are an enormous amount of good open source project for Java. So, seeing java libraries used in simil-pascal code (is not Delphi’s Pascal, but enough similar), is nice. In this way, you can use all the java libraries in Pascal!
I’d like to have this integration in Delphi IDE too with a good designer for Android activities.

I’m testing Oxygene for Java (form RemObjects) for a couple of things, specifically Android related.
This is my first console project in Oxygene for Java, just to see some code.

Oxygene for Java - Simple console app using specific Java libraries
Oxygene for Java – Simple console app using specific Java libraries

 

IMHO there is an enormous potential for the Delphi developer and for all the developers that need a unique language to do server, mobile and native ultra fast app.

I dream to have this technology into the Delphi IDE.

App Android ITDevCon2011 disponibile sul Market (ITALIAN)

Manca solo una settima all’inizio di ITDevCon2011. Per permettere a tutti gli iscritti (e far decidere chi è ancora indeciso) di sfruttare al meglio i due giorni di intensa formazione, abbiamo appena pubblicato l’applicazione ITDevCON2011 sul’Android Market.
Trevete il programma completo della conferenza, i profili degli speaker e informazioni sugli sponsor.
Inoltre, potrete definire i vostri speech preferiti in modo da essere avvisati subito prima dell’inizio dello speech.
Potrete votare e commentare ogni speech. Potete commentare da subito inserendo le vostre aspettative per lo speech o alcune delucidazioni sul contenuto. Il voto invece sarà possibile solo a speech avvenuto.

Dal punto di vista tecnico, questa applicazione Android utilizza un servizio REST scritto con Delphi utilizzando DataSnap e i Mobile DataSnap connectors per Android.
Per chi fosse interessato al “Making”, durante la conferenza potrà assistere allo speech di Salvatore Sparacino che illustrerà i vari step dello sviluppo e le soluzioni tecnologiche adottate.
Per definire il vostro profilo, votare e commentare, dovrete utilizzare il codice fornito al momento dell’iscrizione. Se non siete partecipanti, o ancora non vi è arrivato il codice di accesso, potete utilizzare l’applicazione come “anomymous”. In questo caso non potrete salvare i vostri speech preferiti Né votare o commentare.

Dashboard

La time table
Speaker details
Dettagli dello speaker (in questo screenshot, DavidI)

Il link da dove installare l’applicazione è il seguente:
https://market.android.com/details?id=it.bittime.itdevcon2011

Happy ITDevCon2011

ITDevCon2011 Android App

In less that a week, ITDevCon2011 will begin. To allow all members (and to let decide who is still undecided) to take advantage of the two days of intense training, we have just published the application ITDevCON2011 on the Android Market. You’ll find full conference program, speaker profiles and information about the sponsors.
In addition, you can define your favorite speeches in order to be alerted immediately before the start of the speech.

You can vote and comment every speech. You can comment now by entering your expectations for the speech or some clarifications on the content. The vote, however, is allow only after the speech.
From a technical standpoint, this Android application uses a Delphi DataSnap REST service and the DataSnap Mobile Connectors for Android.

For those interested in the “Application Making Of” during the conference may attend the speech of Salvatore Sparacino illustrating the various steps of development and the technological solutions adopted. Very cool! Salvatore will talk about a REAL app, not only a demo!

To define your training profile, add rates and comments, you have to use the code provided at registration. If you’ll not attend, or you have not received your access code, you can use the application as “anomymous.” In this case, you cannot save your favorite speeches or votes or comments.

Dashboard

The time table
Speaker details
Speaker details (here DavidI)

The link to install the application is as follows:
https://market.android.com/details?id=it.bittime.itdevcon2011

Happy ITDevCon2011!

AndroidConference in Italy – Call4Papers

The Android Conference

Yes! This is a great news! Before the two-days conference dedicated to Delphi, this year there will be the AndroidConference.

The Android Conference

The Android Conference will be a conference focused on Google Android development. Android is one of the most popular OS in the world. Now you can use it for your mobile applications.

And now, the “official” Call4Papers Announce

Dear potential AndroidConference speaker,
I’m building the agenda for the first Android Conference in Italy that will be held in late October in Verona. Dates will be announced ASAP.
The call for papers is officially open right now, so if you want to propose some speeches, I’ll be glad to evaluate them.

For the Call4Paper I need:
• Title (for every talk)
• Abstract (for every talk)
• Difficulty level (for every talk. Difficulty level is a scale from 1 to 3 with the following mean: introduction, intermediate, advanced)
• Speaker’s photo
• Speaker’s profile
I’m looking forward to your proposal. The call4papers ends June 30th, 2011.
Please, send your proposal to this email address.
Proposals will be evaluated and the speakers will be contacted ASAP.
This year topics will be the following:

Topics
– Android Fundamentals
– Android Advanced
– Working with Android Sensors
– Android@Home
– Games
– OpenGL
– Android ADK
– Android Market best practices
– Design UI Pattern
– Optimizing you app for the mobile world
– Developers Tools
– 3rd part libraries
– Android NDK
– The WebView World
– Using WebServices
– SOA and ROA
– HW integration

Target audience
– Software architects
– Software developers
– Project managers
– IT managers
– Trainers
The conference web site is http://www.itdevcon.it (still under construction).
Thanks and hope to see you at AndroidConference 2011.

Tomorrow the webinar: “Developing Application Services using PHP Servers and Android Clients”

Developing Application Services with PHP Servers and Android Phone Clients
Developing Application Services with PHP Servers and Android Phone Clients

In this webinar I’ll show how to develop Android application talking with REST PHP WEB Services. After introducing the basic concepts, attendees of this session will be taken through how to REST-enable the server application, before building the client application targeting an Android phone.

Topics covered in this webinar include:

  • Introduction to REST and JSON support in PHP
  • Introduction to Android client development
  • Creating a REST web service with RadPHP
  • Connecting from an Android application to the REST web service

Companion White Paper, Videos and Source Code Visit the RAD Studio in Action – PHP and Android Resource Center for additional information on this topic, including an in-depth technical white paper, example source code and a video series on building applications with PHP and Android.

More info on http://www.embarcadero.com/rad-in-action/php-android

Developing Application Services with PHP Servers and Android Phone Clients

My new white paper about “Developing Application Services with PHP Servers and Android Phone Clients” is on line under the Embarcadero RAD-in-Action initiative.

Developing Application Services with PHP Servers and Android Phone Clients
Developing Application Services with PHP Servers and Android Phone Clients

Are (or will be) available:

  • The White Paper
  • The complete source code from the white paper
  • 2 videos showing a complete (obviously very simple) Android application interfacing with a PHP REST web service (developer with RAD PHP XE).
  • A webinar (9th february)

In bit time we are heavily working with the Android operating system used in conjunction with DataSnap or PHP services.

This RAD-in-Action initiative (sponsored by Embarcadero) should be useful for all who want to start to work with Android and REST web services developerd with (RAD)PHP or Delphi Datasnap.