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

2 comments:

  1. for the dropbox is not working for now.
    this code works for android phone or only glass?

    i need send a image direct to dropbox but i dont find any example on the internet, if you know how send a image via intent to dropbox send me pls. many thx

    ReplyDelete
  2. That was a workaround I found two years ago specifically crafted to work on Google Glass. Personally I have not tested it outside the gdk (glass development kit) but (at that time) it should have worked on the Android regular sdk too. Probably some of the functions in the API Are changed so you need to update this fragment of code accordingly.

    ReplyDelete