4

I'm trying to make a HelloWorld application for Google Glass by using the GDK provided.

This is the entire codestack, I'm trying to work out the way to program this. Compiling doesn't give any errors but running it does.

package leagueMatch;

import com.google.android.glass.timeline.LiveCard;
import com.google.android.glass.timeline.TimelineManager;
import com.luisdelarosa.helloglass.R;

import android.os.Bundle;
import android.os.IBinder;
import android.app.Activity;
import android.app.Service;
import android.content.Intent;
import android.graphics.Color;
import android.view.Menu;
import android.widget.RemoteViews;

public class MainActivity extends Service {
    String blue_team, purple_team, mvp, casters;
    int blue_kills, purple_kills;

    private LiveCard mLiveCard;
    private TimelineManager mTimelineManager;
    private RemoteViews mViews;

    private static final String TAG = "LeagueMatchInfo";
    private static final String LIVE_CARD_ID = "leaguematch";

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate();
        //mTimelineManager = xxxxxx;

        mViews.setTextViewText(blue_kills, "Lol, Let's see if this works");
        mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_ID);
        mLiveCard.setViews(mViews);

        mLiveCard.setDirectRenderingEnabled(true);
        mLiveCard.publish(LiveCard.PublishMode.SILENT);
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        return true;
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }    
}

Isn't this supposed to launch a card which says "Lol, let's see if this works?"

honk
  • 7,217
  • 11
  • 62
  • 65
HelloWorld
  • 83
  • 8

2 Answers2

15

I created a Hello World project on GitHub.

Start the app by saying "ok glass, hello world" or click on Hello World card shown on the timeline.

The live card has an option menu with two choices:

  1. Say Hi
  2. Close app

Please mark as answer if this helps.

display name
  • 3,926
  • 2
  • 23
  • 51
2

It looks like you're conflating concepts from activities and services. You're right to be using a service to maintain the LiveCard. But you should override the onStartCommand method to publish the card when the service is launched. Please see the source code for the Compass, Stopwatch, and Timer for more examples.

Tony Allevato
  • 6,369
  • 1
  • 27
  • 33