4

Glass GDK here. Trying to insert a livecard using remote views from service. I'm launching service via voice invocation. The voice command works, however it appears my service is not starting(no entries in log). Service is in android manifest. Below is code:

public class PatientLiveCardService extends Service {

private static final String LIVE_CARD_ID = "timer";


@Override
public void onCreate() {
    Log.warn("oncreate");
    super.onCreate();
}

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

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    publishCard(this);

    return START_STICKY;
}

@Override
public void onDestroy() {
    unpublishCard(this);
    super.onDestroy();
}



private void publishCard(Context context) {
    Log.info("inserting live card");
    if (mLiveCard == null) {
        String cardId = "my_card";
        TimelineManager tm = TimelineManager.from(context);
        mLiveCard = tm.getLiveCard(cardId);

        mLiveCard.setViews(new RemoteViews(context.getPackageName(),
                R.layout.activity_vitals));
        Intent intent = new Intent(context, MyActivity.class);
        mLiveCard.setAction(PendingIntent
                .getActivity(context, 0, intent, 0));
        mLiveCard.publish();
    } else {
        // Card is already published.
        return;
    }
}

private void unpublishCard(Context context) {
    if (mLiveCard != null) {
        mLiveCard.unpublish();
        mLiveCard = null;
    }
}

}

Here is AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO" >
</uses-permission>

<application
    android:name="com.myApp"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
      <activity
        android:name="com.myApp.MyActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape" >
    </activity>

    <service android:name="com.myApp.services.MyService" 
         android:enabled="true"
         android:exported="true">
        <intent-filter>
            <action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
        </intent-filter>

        <meta-data
            android:name="com.google.android.glass.VoiceTrigger"
            android:resource="@xml/voice_trigger_get_patient" />
    </service>

</application>

Patrick Jackson
  • 18,766
  • 22
  • 81
  • 141
  • Where do you declare MyActivity? Also, can you make sure to declare it in your manifest as well? Since you didn't set the publish mode as "nonSilent", the LiveCard will be publish silently, meaning that you will need to scroll to the left of the clock to see it. – Alain Nov 20 '13 at 16:01
  • Just added MyActivity to the manifest. It was in my code just had removed it to make it easier to read. I've scrolled to left and it is not there. – Patrick Jackson Nov 20 '13 at 16:16
  • Appears to be an issue with the voice input. I removed the line from my voice_trigger xml and now it works. Same was duplicated with the timer example if I added an line. Is there another permission required? – Patrick Jackson Nov 20 '13 at 16:42
  • The tag, along with the "prompt" attribute is used when your Glassware requires voice input before being invoked, the same way "Allthecooks" works when you do: "Ok Glass, find a recipe for...". – Alain Nov 20 '13 at 16:59
  • Yes, I know. That is what I need. When I remove the voice input, the livecard is inserted. When the voice input is invoked, the card is not inserted... – Patrick Jackson Nov 20 '13 at 17:00
  • Seems like you've found a bug: the service is not invoked after the voice input is done. As a workaround, have your point of entry be an Activity that processes the text input, starts the service and finishes itself. – Alain Nov 20 '13 at 17:32
  • @alain thanks for the quick response. Should I file a bug report? Make this an answer and I will accept it. – Patrick Jackson Nov 20 '13 at 18:57

1 Answers1

4

This is a bug with XE11: the service is not started after the speech recognizer is complete.

As a workaround, you can have your voice trigger start an Activity which:

  1. Processes the recognized speech in onResume.
  2. Once the speech is processed, starts your Service with startService.
  3. Calls finish to jump to the published LiveCard.
Alain
  • 6,044
  • 21
  • 27
  • In that case will onStartCommand get invoked? For me, onStartCommand is getting invoked as I checked by placing loggers. But still the Live Card is not getting published. Code looks the same above. The card simply displays the voice command and does not go anywhere from there. – sivag1 Dec 08 '13 at 16:12
  • Went ahead and tried this workaround. The intermediary activity starts and finishes. onStartCommand of the service is invoked again, but no card is published. – sivag1 Dec 08 '13 at 16:26
  • Here is me again, I found my RemoteViews being null causing the above mentioned symptoms. Problem solved now. Thanks! – sivag1 Dec 08 '13 at 16:58