Reputation: 1459
From the sample app for google glass in java, I found it is working through JSP and servlet. So I can create a timelineitem and set text in to it
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
TimelineItem timelineItem = new TimelineItem();
timelineItem.setText("My Sample Project");
MirrorClient.insertTimelineItem(credential, timelineItem);
response.sendRedirect(WebUtil.buildUrl(request, "/second.jsp"));
}
and from jsp page i can catch the time line and get value from it, like
<%
if (timelineItems != null && !timelineItems.isEmpty()) {
for (TimelineItem timelineItem : timelineItems) {
%>
<div class="container">
<div class="row">
<div class="span4">
<h2>Timeline 2</h2>
<h3><%=StringEscapeUtils.escapeHtml4(timelineItem
.getText())%></h3>
</div>
</div>
</div>
<%
}
}
%>
So now I want to do something advance like bundle of timelines, set background image, custom menuitem, voice command etc.
But in tutorial for advance job i found it is using some JSON format like for menuitem
HTTP/1.1 201 Created
Date: Tue, 25 Sep 2012 23:30:11 GMT
Content-Type: application/json
Content-Length: 303
{
"text": "Hello world",
"menuItems": [
{
"action": "REPLY"
}
]
}
So how I do such of thing? what should I write in servlet and how I get value from jsp page? Should I generate json from servlet and directly write in response or something else
Upvotes: 2
Views: 177
Reputation: 50701
There are a couple of things in your code samples that are a bit misleading and confusing, so lets break them down.
Although the Java example uses a Servlet, which makes sense since it is intended as a server-side operation, it is not using JSP for the Glass portion itself. This is just for what is sent back to show the user.
In the first example, it is the call to MirrorClient.insertTimelineItem()
that does the work of sending the card to Glass. You created this card by creating the TimelineItem and setting fields on this item.
You don't indicate where your third example comes from, exactly, although most Mirror API documentation includes examples for multiple languages, including the raw HTML with JSON (which you quoted) and Java. See, for example, https://developers.google.com/glass/v1/reference/timeline/insert#examples which has a more complete Java example that both sets text on the card and sets notification information. There are other getters for the various other attributes mentioned on that page as well.
The full JavaDoc for the Mirror API Java Library is at https://developers.google.com/resources/api-libraries/documentation/mirror/v1/java/latest/
Upvotes: 1