2014-01-16

How to upload files using google drive from glass

As there is no way of using Intent.ACTION_SEND on Google Glass I found a tricky workaround to upload files generated by your custom apps directly on Google Drive.


1) Download google drive apk from here
2) In your Activity:

import android.support.v4.app.ShareCompat;

Uri pdfUri = Uri.parse("file://sdcard/sdcard0/test.pdf");                
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
                                     .setText("Share PDF doc")
                                         .setType("application/pdf")
                                         .setStream(pdfUri )
                                         .getIntent()
                                 .setPackage("com.google.android.apps.docs");

startActivity(shareIntent);

If you need to upload data from a Service instead of an Activity all you have to do is creating a "dummy activity", insert the above ShareCompat code in the onCreate() method and put finish() after the startActivity(shareIntent) command.


Other Intents can be targeted with similar code, changing the package name, e.g.
  • com.dropbox.android = Dropbox
  • com.android.bluetooth = Bluetooth
  • com.android.email = Email
  • com.google.android.gm = Gmail
  • com.microsoft.skydrive = Skydrive
  • com.google.android.apps.docs = Googledrive

2014-01-03

Opening camera service after voice trigger

Today I added camera support to my google glass app.
The application worked like a charm when launched it through the custom launcher but I was surprised by the fact that starting it with the voice command "ok glass" resulted in a "failed to connect to camera service" Runtime Exception.

Surfing the net, I discovered that this is a common issue (take a look at this).
It seems that the delay between the voice recogniser closing event and the camera open event is causing a memory overload.
Someone succeeded in avoiding the problem by pausing the app for a certain time (1000 Milliseconds) before opening the camera.

However this solution didn't work for me, maybe because I'm using XE12. However I found out that if you say "Ok glass" and wait for 2 seconds before you say the app name it works flawlessly.

As this is not a very "professional and scientific" solution I will review this problem in the future, so stay tuned.

2014-01-02

Fixed broken custom launcher for XE12 - bluetooth keyboard pairing

After the release of XE12 (the one which broke the custom launchers) I was looking for a way to fix the problem of launching Settings.apk in order to pair my i10 bluetooth keyboard with Google Glass.
Googling a little bit I came to the following solution and it seems to work fine:

  1. Download Glass Launcher  (which has been updated for XE12) and import it in Eclipse as a new project.
  2. Right click the project you just created and select "android tools" and then "add support Library...". if you skip this step Eclipse will not succeed in converting the source code into dex
  3. Now install Settings.apk 
  4. Now turning on our Glass and swiping left you'll have the possibility of launching Settings from the Glass Launcher Card.
  5. Open Settings, tap on bluetooth and start inquiring for nearby devices.
  6. Select your bluetooth keyboard and follow the on-screen instructions to pair it.