我正在尝试制作我的第一个Google Glass应用程序(如果您算上Hello World项目:),则为第二个应用程序),并且需要一点帮助。我创建了第一部分,结果还不错(该应用程序同时显示在语音命令列表和"启动器"中,我可以运行它/与之交谈),所以我非常兴奋我能走到这一步!我的问题是,如何将卡片发布到时间线?
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);
}
}
在 Java 方面,我有点菜鸟,所以我边走边学......
此外,值得注意的是,我尝试创建的应用程序是一个简单的记事本应用程序,用户将在其中说出文本,并将新卡片添加到时间线以供将来参考,其中包含语音文本。我在 Eclipse/ADT 中使用 GDK 先睹为快。
提前感谢您的任何和所有帮助!
若要添加发布到时间线的卡片,需要使用 https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/timeline/TimelineManager 中记录的 GDK 时间线管理器 API
例如:
mTimelineManager = TimelineManager.from(this);
mTimelineManager.insert(card);
请注意,使用卡片创建的时间轴上的卡片(静态卡片)仅保留 7 天 (https://developers.google.com/glass/design/ui/static-cards)。