2

I have a card that is being inserted in my timeline by the mirror api.

The card has 3 options: SCAN, REPLY, DELETE.

Expected-> Barcode Test[SCAN, REPLY, DELETE]
Received-> Barcode Test[REPLY, DELETE]

The Reply and Delete options only return on menu item. If i change 'OPEN_URI' to 'CUSTOM" it returns but does not do what I hope to do, which is open my android.scan.(this is present no my device)

I followed similar steps to here and on the Mirror-API docs about creating the menuItems https://developers.google.com/glass/v1/reference/timeline#menuItems

Opening GDK Glassware through Mirror API Glassware MenuItem

 .mirror.timeline.insert(
    {
        "text": "Barcode Test",
        "callbackUrl": "https://mirrornotifications.appspot.com/forward?url=http://localhost:8081/reply",
        "menuItems": [
            {
              "action": "OPEN_URI",
              "id": "complete",
              "payload": "com.google.zxing.client.android.SCAN",
              "values": [{
                "displayName": "Scan",
                "iconUrl":"com.google.zxing.client.android.SCAN"
              }]
            },
            {"action": "REPLY"},
            {"action": "DELETE"}
        ]
    }
  )
Community
  • 1
  • 1
StanleyZheng
  • 4,008
  • 3
  • 21
  • 24

1 Answers1

3

The OPEN_URI menu item requires that you specify a valid URI for the payload.

To use the web browser to open a page, this will look just like what you'd put into a normal desktop web browser so your insertion would look something like that:

 .mirror.timeline.insert(
    {
        "text": "Barcode Test",
        "callbackUrl": "https://mirrornotifications.appspot.com/forward?url=http://localhost:8081/reply",
        "menuItems": [
            {
              "action": "OPEN_URI",
              "id": "complete",
              "payload": "http://example.com",
              "values": [{
                "displayName": "Scan",
                "iconUrl":"http://example.com/icon.png"
              }]
            },
            {"action": "REPLY"},
            {"action": "DELETE"}
        ]
    }   )

You can also use OPEN_URI to initiate an activity on an android app using a custom protocol.

I don't know much about the implementation of the scanner you are trying to use, but here's how you'd wire it up for your own GDK app.

You need to specify the custom protocol in your AndroidManifest.xml by adding something like this:

<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.BROWSABLE" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:scheme="exampleprotocol" />
</intent-filter>

You must specify a URI with that protocol in your Mirror API timeline item. Your insert code might look something like this:

 .mirror.timeline.insert(
    {
        "text": "Barcode Test",
        "callbackUrl": "https://mirrornotifications.appspot.com/forward?url=http://localhost:8081/reply",
        "menuItems": [
            {
              "action": "OPEN_URI",
              "id": "complete",
              "payload": "exampleprotocol://scan",
              "values": [{
                "displayName": "Scan",
                "iconUrl":"http://example.com/scan.png"
              }]
            },
            {"action": "REPLY"},
            {"action": "DELETE"}
        ]
    }
  )
mimming
  • 13,974
  • 3
  • 45
  • 74
  • Hi @jenny thanks for the help. The problem still persists, does the 'OPEN_URI' protocol do some sort of client or server side validation? I think its an issue with the payload not being properly formatted. Mirror tosses the option out. "payload": "SCAN://com.google.zxing.client.android.SCAN", – StanleyZheng Mar 03 '14 at 16:25
  • yeah i copy pasted your example on the custom protocol uri and either the server or the glass parsed the request, does the mirror api or the device perform these actions? It skips these options – StanleyZheng Mar 03 '14 at 16:46
  • Thanks it worked like a charm! I only had to specify the protocol to launch my app. "payload": "exampleprotocol". I had trouble because the client was parsing for intents it didn't believe exist – StanleyZheng Mar 05 '14 at 16:57