Menu Item for “OPEN_URI” not present in menuItems return

家住魔仙堡 提交于 2019-11-30 19:38:44

问题


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"}
        ]
    }
  )

回答1:


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"}
        ]
    }
  )


来源:https://stackoverflow.com/questions/22105005/menu-item-for-open-uri-not-present-in-menuitems-return

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!