Wireless Android Debugging with Delphi xE5

Previously I blogged about how to connect to an emulator on a remote (or the host) machine. That also works for hardware connected to remote machines. But sometimes you want to work with hardware that isn’t even connected at all. Not to worry, here is how to wirelessly connect and debug with your favorite development tool. One note though, WiFi slower than a USB connection, so you will see a little delay sometimes.


  • A machine (Mac or PC) you can connect the Android device to that has ADB (Android Debug Bridge) installed. This is part of the Android SDK. As well as necessary ADB USB Drivers (required on Windows). This can be your development machine, or another machine.
  • A non-segmented wireless network that both your development machine and Android device are connected. (Segmenting prevents two connected devices from connecting to each other).

These commands work with ADB (Android Debug Bridge). It is easiest if you add it to your path. By default it is found in the following location, but you can install it anywhere on your system (Select the “Use An Existing IDE” option when downloading).

C:\Users\Public\Documents\RAD Studio\12.0\PlatformSDKs\adt-bundle-windows-x86-20130522\sdk\platform-tools

First you need to connect your Android device to any computer. With USB debugging turned on, verify you have access to the device via ADB with the following command:


adb devices


List of devices attached 
8605fa72        device

If the list is empty, then you need to enable USB debugging and make sure you have the USB ADB Bridge driver for your device installed.

Once ADB is setup, you can get the IP address with the following command:

adb shell netcfg|grep wlan0

Which should give you output like:

wlan0  UP  0x00001043 2a:32:11:42:aa:3c

Then put the device in TCPIP mode with the command:

adb kill-server
adb tcpip 5555

Then on your machine that is running Delphi XE5 go to the command window and type (with the IP address from above):

adb connect

Then you can verify it worked from that same command prompt


adb devices


List of devices attached   device

And now you can connect to that device wirelessly from Delphi. Like I mentioned before, this is slower, so expect some delays on deploy and responding to breakpoints.

There is some more information on Stack Overflow, including some different options if you have a rooted Android device.


Things I Learned from Delphi CodeRage 8

Mostly from CodeRage 8, but some is from my time working for Embarcadero. I believe I’ve presented at every CodeRage, but this is my first time on the other side. It is also the biggest CodeRage by a significant margin. I’m sure the two events are unrelated, but it is still exciting.

  • Delphi can do functional programming, and it is really cool.
  • Cary Jensen is really excited about FireDAC – and so is everyone else, because FireDAC is really cool. He’s so excited he might cut his hair off . . .
  • There are a lot of really smart and very nice people working for Embarcadero.
  • No matter how easy you find it to understand someone, there is somebody else who has a hard time with their accent, speed, or terminology.
  • There is still more that I don’t know about Delphi then I do. And I think that is a good thing.
  • You really shouldn’t use “with” in your code, especially during a presentation that occurred after Alister Christie‘s session on “anti-patterns.”
  • The Tag property is useful, but no one wants to admit it.
  • Delphi makes it easy to make nice UI and ugly UI. I like that it is flexible.
  • If you use something wrong it will be slow. If you test you can probably find a faster way.
  • Two people can present on the same thing and have different sessions while two other people can present on two different things and have surprising overlaps.
  • REST and JSON are great, but XML and SOAP are still around and in use.
  • If you want to scroll it, use a TListView. Otherwise use a TListBox.
  • When it comes to making custom controls, in any framework, Ray is still the guy.
  • It is a lot more work than I expected to run CodeRage, but also a lot more fun.
  • If you know what you are doing, it is pretty easy to access any iOS or Android API from Delphi.
  • You can use FireMonkey to make a pretty good mobile game, but it still isn’t recommended.
  • Encrypt your customer’s data, or you can get a huge fine.
  • Everyone always likes a good benchmark or comparison, but they don’t really tell you anything.
  • David I. really is as great of a guy as everyone says he is, but even 3 days of CodeRage will wear him out.
  • The Android Emulator is really slow and unresponsive, and no one seems to know why.
  • There usually is more than one way to do something. And just when I think I realized a smart way to do something, someone else will point out an easier way.
  • Replay videos are never online fast enough.
  • Making a good video to explain a technical topic is way more work than anyone realizes, even people who have done it a hundred times. And when you are done you are rarely satisfied with it.
  • GoToWebinar is a pain, but so far it seems to be the best option.
  • Even in a pre-recorded video, people will still help you find the typos in your code.
  • Questions can take longer than the session the questions are about.
  • Delphi developers really are amazing!

And some answers to frequently asked questions:

  • The code will usually be on the presenters blog.
  • Replays will be a couple weeks.
  • Turn on “Use Host GPU” in your Android emulator and don’t run your VM in an Emulator. Better yet, buy an Android device. The emulator is slow for everyone, which is why most Android developers don’t use it.

I learned a lot more, but those were the memorable bits that came to mind.

What did you learn?

Android Conferences iOS Mobile

Sending a URL to Another App on Android and iOS with Delphi XE5

Here is the source code for my Open and View URL library from my CodeRage 8 session “Beyond the App”. Here is a download of the example app. I’ll see about posting it to a SVN repository too so it can grow and evolve. Thanks to Al Mannarino for his code that started this!

Note the code is using TidURL.URLEncode on all URLs. I found it is only required on the maps for iOS (iOS doesn’t like spaces) but may be causing trouble with the geo:// on Android.

Some example protocols

  • http, tel, sms, fb, mailto, twitter, geo, etc.

Example URLs

  • – Common to both iOS & Android –
  • tel://(415)834-3131
  • sms://1234
  • (This opens with the Twitter client on Android)
  • mailto://
  • twitter://user?screen_name=coderage
  • fb://profile/34960937498 (get the UID from or for whatever page you are looking for)
  • – iOS Specific –
  • Scotts Valley Drive, Scotts Valley, CA 95066 (this needs the URL encode – Apple has some additional APIs that are recommended.)
  • – Android Only –
  • content://contacts/people/
  • content://contacts/people/1
  • geo://0,0?q=5617 Scotts Valley Drive, Scotts Valley, CA 95066
  • geo://46.191200, -122.194400 (I think this one doesn’t like the URLEncode)
unit OpenViewUrl;


// URLEncode is performed on the URL
// so you need to format it   protocol://path
function OpenURL(const URL: string; const DisplayError: Boolean = False): Boolean;


  IdURI, SysUtils, Classes, FMX.Dialogs,
  FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.Net, Androidapi.JNI.JavaTypes;
  Macapi.Helpers, iOSapi.Foundation, FMX.Helpers.iOS;

function OpenURL(const URL: string; const DisplayError: Boolean = False): Boolean;
  Intent: JIntent;
// There may be an issue with the geo: prefix and URLEncode.
// will need to research
  Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW,
    on e: Exception do
      if DisplayError then ShowMessage('Error: ' + e.Message);
  NSU: NSUrl;
  // iOS doesn't like spaces, so URL encode is important.
  NSU := StrToNSUrl(TIdURI.URLEncode(URL));
  if SharedApplication.canOpenURL(NSU) then
    if DisplayError then
      ShowMessage('Error: Opening "' + URL + '" not supported.');
  raise Exception.Create('Not supported!');

Android iOS Mobile

Reading Barcodes with XE5 – Preliminary post

Fernando Rizotto has an example of using XE4 on iOS to read a barcode. He is using an iOS specific library. Another library that is available on both iOS and Android is OpenCV. It is a full open source computer vision library with a lot of great features, one of which is reading barcodes.


Fun with external Java libraries on XE5 by Paul Foster

Paul Foster shared his experiences working with External Java libraries on Android with XE5 on Google+. Here is a PDF he put together for you to download.


CodeRage 8 Is Coming!

CodeRage 8 is right around the corner!

CodeRage 8 - October 15-17, 2013This October 15th through the 17th join us for 3 full days of virtual conference sessions filled with mobile development topics using Delphi and RAD Studio XE5.



6 Stages of Debugging

My friend came up with the 6 Stages of Debugging: 

  1. That can’t happen
  2. That doesn’t happen on my machine.
  3. That shouldn’t happen.
  4. Why does that happen?
  5. Oh, I see.
  6. How did that ever work?

Update: Looks like this is an old, but still relevant list.

Although you could apply the Kübler-Ross model too:

  1. Denial – It must be user error! Are we sure their system is supported?
  2. Anger – By filing this bug you have questioned my family honour. Prepare to die!
  3. Bargaining – What if we just update the documentation? Can we tell the users this is a feature?
  4. Depression – All my code is broken! I have no idea what I am doing! I’m going to lose my job.
  5. Acceptance – Oh, that was easy to fix.

Do you ever find yourself in these stages?


Delphi XE5 Android “Uses Permissions”

The permissions required by a Delphi XE5 Android application are defined through the Uses Permissions dialog. It is found under Project -> Options… [Shift+Ctrl+F11].


RAD Studio XE5 Android "Uses Permissions" Dialog

If you select other Targets besides Android then the list is blank, for now. By default the following common permissions are selected. If you do not select a permission then any calls you make that require that permission will fail. The “Internet” permission is required for any network access, even your local network.

If you scroll down the list you will see an Advanced node which contains permissions that are less commonly used permissions. For many apps you will never need to change these permissions, but your users may notice the “services that can cost money” warning next to Call phone and Internet permission request, so you may want to remove those.

The requested permissions are automatically added to the AndroidManifest.xml file, which is read by the Android operating system and Google Play store to know which permissions your app requested.