Hello World For Google Glass

≯℡__Kan透↙ 提交于 2019-12-25 07:09:45

问题


I'm trying to build a simple Hello World GDK program for Google Glass. I've looked up everywhere, but all the samples I could find used "Timeline Manager", which was removed by Google after XE 16.

What I'm trying to do is to create a live card that shows texts (Hello world!) in the middle. I've tried to modify codes from HERE (HuskyHuskie's answer) and HERE (IsabelHM's answer)

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

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

Also, I'm relatively new to Android. I don't quite understand how R.id.XXXX and R.layout.XXXX are missing from the resource. Do you need to define it in Manifest or what else?

The following is the onStartCommand method:

@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;
}

回答1:


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:

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

See the post HERE for reference.




回答2:


I strongly recommend using our official samples available on GitHub and reading our documentations as all of those caveats are explained and handled.

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.

  1. Open 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.
  5. Select the Immersion Activity or the Simple Live Card template
  6. Build and run your new Hello World project on Glass!


来源:https://stackoverflow.com/questions/24797536/hello-world-for-google-glass

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