Reputation:
I am trying to make my first Google Glass app (second if you count the Hello World project :) ), and need a little help. I created the first part, which turned out okay (the app shows up in both the voice command list and "launcher" and I can run it/speak to it) so I am pretty excited that I got this far! My question is, how do I get the card published to the timeline?:
package com.test.glass.glassnotes;
import java.util.ArrayList;
import com.google.android.glass.app.Card;
import android.app.Activity;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get voice input results
ArrayList<String> voiceResults = getIntent().getExtras()
.getStringArrayList(RecognizerIntent.EXTRA_RESULTS);
String voiceString = "";
for(String str:voiceResults){
voiceString = voiceString + " " + str;
}
voiceString = voiceString.trim();
//Create card
Card card1 = new Card(this);
card1.setText(voiceString);
card1.setFootnote("GlassNotes");
View card1View = card1.toView();
// Display card
setContentView(card1View);
}
}
I am a bit of a noob when it comes to Java, so I'm learning as I go along...
Also, it might be worth noting that the app I am trying to create is a simple notepad app, where the user would speak text and a new card would be added to the timeline for future reference, containing the spoken text. I am doing this in Eclipse/ADT with the GDK Sneak Peek.
Thanks in advance for any and all of your help!
Upvotes: 1
Views: 84
Reputation: 1804
To add a card published to the timeline, you need to use the GDK TimelineManager API documented at https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/timeline/TimelineManager
For example:
mTimelineManager = TimelineManager.from(this);
mTimelineManager.insert(card);
Be aware that the cards on the timeline created using Card (the static cards) remain there only for 7 days (https://developers.google.com/glass/design/ui/static-cards).
Upvotes: 2