Saturday, January 31, 2015

Outdated Android Blog Posts

Just an FYI - my android programming posts are pretty outdated, so they can probably be ignored.  I just noticed over 5000 views on my blog dashboard - yikes - I hope I have not led those readers astray.  Happy coding.


Sunday, January 27, 2013

Running HelloGalaxy App on my Phone

In my last blog post I showed how to run the HelloGalaxy App directly from eclipse onto the AndroVM.  In this post I will show how to run the app directly on my Galaxy S3 phone from Eclipse.

The long way around is to copy the .apk file onto your phone using Android the Android File Transfer app (See notes from my previous post about this app).  For example, of you copy the HelloGalaxy.apk to your Downloads folder on your device and then browse via "My Files" app on your phone and attempt to launch / install the app, you will get a bunch of warnings about installing apps from unknown sources.

The easy way is to enable debugging on your phone.

Select Settings, then choose developer options and select USB Debugging mode.



Then connect your phone with the USB cable and thereafter the steps are similar as described in my previous post about running the app on a virtual device directly from eclipse.

The ADB will automatically connect to your device and when you run your app from Eclipse, you will see your phone in the Android Device Chooser.

Here is the final result of the App running on my phone.


Happy Coding ;)

Run Android App from Eclipse on AndroVM Virtual Device

In this post I will show how to run my hello world app called HelloGalaxy from Eclipse on my virtual Android device. (I described how to build, package and deploy the app in previous posts).

Fire up AndroVM and note the IP Address of the device as described in my previous post, where I described how to deploy your app to AndroVM .

Connect to your running VM on the command line.


cd ~/develop/adt-bundle-mac/sdk/platform-tools$

$ ./adb connect 192.168.56.101

To check that you are connected, simply execute:


$ ./adb devices
List of devices attached
192.168.56.101:5555 device



Now you can execute your app from Eclipse.  When you select Run-> Run As -> Android Application (as I described in Building HelloGalaxy post).  This will compile, build and package the HelloGalaxy.apk file and pop up a Android Device chooser dialog.



Select the AndroVM device and click OK (You can also check the :Use same device for future launches" to skip the dialog on the next run.

Check the log files in the eclipse console and you should see messages saying: "Uploading HelloGalaxy.apk...", Installing HelloGalaxy.apk...", "Success!", "Starting Activity...", etc.


Thats it.  You may need to bring the AndroVM to the foreground and you should see HelloGalaxy running on the device.

If you make any code changes, simply select Run from the Run menu and your app will be re-compiled, packaged, deployed and executed on the AndroVM.



Monday, December 3, 2012

Mac Disk Image Development with Git


* I copied and edited these notes from: AOSP

Git Development on Mac

In a default installation, OS X runs on a case-preserving but case-insensitive filesystem. This type of filesystem is not supported by GIT and will cause some git commands (such as "git status") to behave abnormally. Because of this, you should always work with the GIT source files on a case-sensitive filesystem. This can be done fairly easily using a disk image, discussed below.

Creating a case-sensitive disk image

You can create a case-sensitive filesystem within your existing OS X environment using a disk image. To create the image, launch Disk Utility and select "New Image".  Using sparse images saves space while allowing to grow later as the need arises. Be sure to select "case sensitive, journaled" as the volume format.
You can also create it from a shell with the following command:

# hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 40g ~/mydisk.dmg

This will create a .dmg (or possibly a .dmg.sparsefile) file which, once mounted, acts as a drive with the required formatting for GIT development. For a disk image named "mydisk.dmg" stored in your home directory, you can add the following to your ~/.bash_profile to mount the image when you execute "mountMydisk"

# mount the file image
function mountMydisk { hdiutil attach ~/mydisk.dmg -mountpoint /Volumes/mydisk; }

Once mounted, you'll do all your work in the "mydisk" volume. You can eject it (unmount it) just like you would with an external drive.

Setting a file descriptor limit

On MacOS the default limit on the number of simultaneous file descriptors open is too low and a highly parallel build process may exceed this limit.
To increase the cap, add the following lines to your ~/.bash_profile:

# set the number of open files to be 1024
ulimit -S -n 1024


Deploy app to Android Virtual Device

This is the easy part.  If you have been following along the previous blog posts, we now have our first Android app called "HelloGalaxy.apk" packaged as an APK file ready to install on run on our virtual Android device (AndroVM on VirtualBox).

To install this package file, which contains the app, icons and metadata, we will need to use a command  line tool called Android Debug Bridge (adb).  This tool that lets you communicate with an Android emulator instance.  If you connect your phone with a USB cable, the adb tool also allows you to connect and install apps directly onto your phone.

To get started, we will need to fire up our Android emulator with VirtualBox.  (In the previous blog post, we showed you how to install and configure AndroVM under virtual box).  When you start the AndroVM with VirtualBox, you will end up on the Android home screen and see the androVM Configuration app.



When you run the androVM Configuration appyou will see the IP address of your Android emulator instance.



Take note of the IP Address.  Now we can run the adb tool.  This command line tool is found in the .../sdk/platform-tools/ folder.

cd to the platform-tools directory and execute the adb connect command.  For Example:

cd ~/develop/adt-bundle-mac/sdk/platform-tools$

$ ./adb connect 192.168.56.101
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
connected to 192.168.56.101:5555

If successful, you will see a message similar to the above.

Now that we are connected to the device, we can install the APK file in our HelloGalaxy project's bin directory that we generated in a previous post where we showed how to "build" the package.

$ ./adb install ../../workspace/HelloGalaxy/bin/HelloGalaxy.apk 
7639 KB/s (179361 bytes in 0.022s)
pkg: /data/local/tmp/HelloGalaxy.apk
Success

If you see the success message, you should be able to see the HelloGalaxy app on the Apps Screen in the emulator.




Click on the app icon to run your first android application.



Nothing too exciting, but we have an App that is up and running.  You can uninstall the app from the emulator by going to Settings -> Apps and selecting HelloGalaxy and click on the Uninstall button.



Note: The adb tool starts up a small background daemon that communicates with the device.  To shut down the adb sever, execute:

$ ./adb kill-server

Thats it.  Now that we know the lifecycle of how to create, build and deploy an Android app, on an emulator, its time to start building something useful and then get it running on my phone.  Stay tuned...



Friday, November 30, 2012

AndroVM Android Virtual Device

After much trial and error, the best solution for my slow Mac is to find an alternative to the QEMU emulators bundled with Android Developer Tools (ADT).

For me, the solution was AndroVM running on VirtualBox.  This will give you a nice fast Ice Cream Sandwich version of Android with the ability to install your apps from the Google Play Store as well as a place to run and test your own apps.

First Download and install VirtualBox from: https://www.virtualbox.org/

Next Download and install the latest AndroVM from: http://androvm.org/
There are several .ova files to choose from for Tablet, Phone and Table or Phone only, with or without the built in Google Apps.  I selected the Phone only version (vbox86p) with Goofle Apps & Houdini.

From VirtualBox, select File -> Import Appliance and select the AndroVM .ova file.
You will now have a VM in VirtualBox ready to run.

If you select Network Settings for this VM, you will notice that there are 4 network adapters.  The first network adapter is not attached and the 2nd adapter is attached to NAT.  Adapters 3 and 4 are not enabled.  In order to connect to this device (once it is running) with the Android developer tools, you will need to attach Network Adapter 1 to "Host-only Adapter"



Fire up the Virtual Android device from VirtualBox by clicking the "Start"
If all goes well, the VM will start and Android will boot up and you will be greeted by the welcome screen asking you to start setting up your new Android (virtual) device.



Run through the setup and you will end up on the home screen where you can start running apps on the new virtual device.



Run the Browser to ensure you have internet connectivity via the NAT Network Adapter.



Now that we have our Virtual Device set up, the next post we will deploy (copy) our HelloGalaxy.apk file onto the virtual device and run our first app.





Tuesday, November 27, 2012

Android File Transfer on Mac with Galaxy S3

I could not get the Android File Transfer app http://www.android.com/filetransfer/ to work on my Mac.
It turns out that Kies application from Samsung was the problem causing conflicts when connecting my S3 to my Mac :(
http://www.samsung.com/us/kies/

You need to un-install Kies using the Uninstaller on the Kies disk image.

  1. Download the Samsung Kies package from the Samsung website:
  2. http://www.samsung.com/uk/support/usefulsoftware/KIES/JSP
  3. Open the downloaded Kies package
  4. Run the "Uninstall" program
The Galaxy device must also be set to "Media Device" Mode (MTP) as this is the protocol used by Android File Transfer. This can be done as follows:
  1. Connect your S3 to your Mac using a USB cable
  2. Touch the notification bar on your phone (the thin bar at the top of the screen containing the time, battery indicator, etc.)
  3. Pull the notification bar down to the bottom of the screen
  4. Select the “Connected as Media Device” or “Connected as Camera” option
  5. Select the “Media Device (MTP)” option (if this is not already selected)

Hope this helps any other frustrated users.  The Android File Transfer App is invaluable.