简体   繁体   English

如何知道Google Glass TimelineManager LiveCard已恢复

[英]How to know Google Glass TimelineManager LiveCard is resumed

I am developing a simple hello world application in Google Glass using Service. 我正在使用Service在Google Glass中开发一个简单的hello world应用程序。 In my application I used TimelineManager to display a LiveCard . 在我的应用程序中,我使用TimelineManager来显示LiveCard I want to invoke a http call when the app is visible to user (I mean when user scrolled from other app to our app). 我想在用户可见该应用程序时调用一个http调用(我的意思是当用户从其他应用程序滚动到我们的应用程序时)。

I know if we use Activity, onResume() invoked automatically, but I am doing it in Service. 我知道我们是否使用Activity,会自动调用onResume(),但是我正在Service中进行。

Please let me know which method will be invoked when app is resumed to user . 请让我知道将应用恢复给用户时将调用哪种方法

public class MyGlassService extends Service {

    private static final String TAG = "SocketService";
    private static final String LIVE_CARD_ID = "livecard";
    private TimelineManager mTimelineManager;
    private LiveCard mLiveCard;
    private TextToSpeech mSpeech;
    private final IBinder mBinder = new MainBinder();

    private TextView txtName, txtBalance;
    private RemoteViews remoteView;
    private WakeLock screenLock;    


    public class MainBinder extends Binder {
        public void sayMessage() {
            mSpeech.speak(getString(R.string.hello_world),
                    TextToSpeech.QUEUE_FLUSH, null);
        }
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mTimelineManager = TimelineManager.from(this);
        mSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                // do nothing
            }
        });

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        remoteView = new RemoteViews(this.getPackageName(), R.layout.activity_main);
        if (mLiveCard == null) {
            mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_ID);
            remoteView.setTextViewText(R.id.name, getString(R.string.pre_screen_msg));
            mLiveCard.setViews(remoteView);

        }
        return START_STICKY;
    }   


    @Override
    public void onDestroy() {
        if (mLiveCard != null && mLiveCard.isPublished()) {
            mLiveCard.unpublish();
            mLiveCard = null;
        }
        mSpeech.shutdown();

        mSpeech = null;
        super.onDestroy();
    }

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

    public String toHexString(byte[] data) {
        String s = new String(data);
        return s;
    }
}

Live cards do not provide precise lifecycle methods like activities do to let you know when a user has scrolled to or away from one. 实时卡不能像活动那样提供精确的生命周期方法,而活动可以让您知道用户何时滚动到一个或滚动一个。

If you would like to see this feature, please post a feature request describing your use case on our issue tracker . 如果您想查看此功能,请在我们的问题跟踪器上发布功能请求,以描述您的用例。

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

相关问题 Google Glass:cardScrollView中的LiveCard - Google Glass : LiveCard in cardScrollView 服务中的Google Glass LiveCard更新列表视图 - Google Glass LiveCard update listview from Service Google Glass如何知道玻璃是否已磨损 - Google Glass How to know if the glass is worn 在取消发布活动卡的先前实例之前,如何在Google Glass中发布活动卡 - How to publish live card in Google Glass before unpublishing the previous instance of the livecard 开发人员指南中的Google Glass LiveCard示例代码是否有错误? - Is there an error on the Google Glass LiveCard sample code on the Developer Guides? 我不知道如何在Google Glass中更改OK Glass短语 - I dont know how to change ok glass phrase in google glass 在Google Glass时间线中拥有卡片而无需使用服务类(或者具有没有强制性的PendingIntent菜单活动的LiveCard) - Having a Card in Google Glass Timeline without using Service class (or having a LiveCard without the mandatory PendingIntent Menu Activity) 在Google Glass应用程序中如何知道用户已转移到新卡上? - How to know a user as moved to a new Card in a Google Glass app? 如何检测真人卡中的手势 - how to detect gestures in a livecard Google Glass:如何在Google Glass上启动联系人应用程序 - Google Glass: How to Launch Contact Application on Google Glass
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM