Google Glass Live Card未插入

时间:2013-11-20 15:33:12

标签: google-glass google-gdk

Glass GDK在这里。尝试使用服务中的远程视图插入livecard。我正在通过语音调用启动服务。语音命令有效,但看起来我的服务没有启动(日志中没有条目)。服务是在android清单中。以下是代码:

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

}

这是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>

1 个答案:

答案 0 :(得分:4)

这是XE11的错误:语音识别器完成后服务未启动。

作为一种解决方法,您可以让语音触发器启动Activity,其中包含:

  1. 处理onResume中已识别的语音。
  2. 处理完演讲后,请使用Service
  3. 启动startService
  4. 致电finish以跳转到已发布的LiveCard