简体   繁体   English

Google Glass的Hello World

[英]Hello World For Google Glass

I'm trying to build a simple Hello World GDK program for Google Glass. 我正在尝试为Google Glass构建一个简单的Hello World GDK程序。 I've looked up everywhere, but all the samples I could find used "Timeline Manager", which was removed by Google after XE 16. 我到处都在查找,但是我可以找到的所有示例都使用了“时间轴管理器”,该工具在XE 16之后被Google删除了。

What I'm trying to do is to create a live card that shows texts (Hello world!) in the middle. 我想做的是创建一个活卡,在中间显示文本(Hello world!)。 I've tried to modify codes from HERE (HuskyHuskie's answer) and HERE (IsabelHM's answer) 我试图从HERE (HuskyHuskie的答案)和HERE (IsabelHM的答案)修改代码

However, no matter what I did, no option or voice command appeared on the glass even though the console showed that the program is installed on device. 但是,无论我做什么,即使控制台显示程序已安装在设备上,玻璃上也没有任何选项或语音命令。

What I mostly modified was take out the TimelineManager part and replace 我主要修改的是取出TimelineManager部分并替换

mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_ID); with mLiveCard = new LiveCard(this,LIVE_CARD_ID); 使用mLiveCard = new LiveCard(this,LIVE_CARD_ID);

Also, I'm relatively new to Android. 另外,我对Android还是比较陌生。 I don't quite understand how R.id.XXXX and R.layout.XXXX are missing from the resource. 我不太了解资源中缺少R.id.XXXX和R.layout.XXXX。 Do you need to define it in Manifest or what else? 您需要在清单中定义它还是其他?

The following is the onStartCommand method: 以下是onStartCommand方法:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
            RemoteViews aRV = new RemoteViews(this.getPackageName(),
            R.layout.card_text);
    if (mLiveCard == null) {
       // mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_ID);
        mLiveCard = new LiveCard(this,LIVE_CARD_ID);

        aRV.setTextViewText(R.id.main_text, INTRO);
        mLiveCard.setViews(aRV);



        Intent mIntent = new Intent(this, MainActivity.class);
        mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |    Intent.FLAG_ACTIVITY_CLEAR_TASK);
        mLiveCard.setAction(PendingIntent.getActivity(this, 0, mIntent, 0));
        mLiveCard.publish(LiveCard.PublishMode.REVEAL);
    } 
    return START_STICKY;
}

Ok I got it to work following THIS 好的,我遵循了这个

Note that the Manifest is not entirely correct. 请注意,清单并非完全正确。 You need to add this line in the Manifest after the XE16 update: XE16更新后,您需要在清单中添加以下行:

    <uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />

See the post HERE for reference. 请参阅此处的帖子以供参考。

I strongly recommend using our official samples available on GitHub and reading our documentations as all of those caveats are explained and handled. 我强烈建议使用我们在GitHub上提供的官方示例并阅读我们的文档,因为所有这些警告都得到了解释和处理。

If you are using the latest version of Android Studio, you can also easily create a new project through our available templates: LiveCard and Immersion . 如果您使用的是最新版本的Android Studio,则还可以通过我们可用的模板LiveCardImmersion轻松创建一个新项目。

  1. Open Android Studio 开启Android Studio
  2. Create a new project 创建一个新项目
  3. Enter your project information: application name, package name, etc. 输入您的项目信息:应用程序名称,程序包名称等。
  4. Select Glass as the form factor: make sure to unselect all the other form factors unless you want to develop for those devices as well. 选择Glass作为外形尺寸:除非您也想为这些设备开发,否则请确保取消选择所有其他外形尺寸。
  5. Select the Immersion Activity or the Simple Live Card template 选择Immersion ActivitySimple Live Card模板
  6. Build and run your new Hello World project on Glass! 在Glass上构建并运行您的新Hello World项目!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM