从 Android Wear Watchface 开始 Activity

Starting an Activity from Android Wear Watchface

我正在尝试从 Android 中的表盘启动 activity 使用以下方式点击佩戴:

            Intent myIntent = new Intent(this, com.jorc.android.wearable.watchface.watchface.MainActivity.class);
            getApplicationContext().startActivity(myIntent);

但是,我得到了这个错误。

Error:(564, 39) error: no suitable constructor found for Intent(DigitalWatchFaceService.Engine,Class<MainActivity>)
constructor Intent.Intent(String,Uri) is not applicable
(argument mismatch; DigitalWatchFaceService.Engine cannot be converted to String)
constructor Intent.Intent(Context,Class<?>) is not applicable
(argument mismatch; DigitalWatchFaceService.Engine cannot be converted to Context)

我的问题是:"Is there a way to start an activity from a watchface"?表盘使用 CanvasWatchFaceService.Engine 扩展 CanvasWatchFaceService。

使用的时候少了一点 Intent myIntent = new Intent(this, ...MainActivity.class) MainActivity.class) 意图是在另一个 class 中创建的,这里是一个匿名内部 class canvas 点击监听器。该代码没有按预期引用 Activity(或上下文)的实例,而是引用匿名内部 class canvas ClickListener.

的实例

所以正确的方法是提供 class 的正确上下文。

 Intent myIntent = new Intent(DigitalWatchFaceService.this, com.jorc.android.wearable.watchface.watchface.MainActivity.class);
 getApplicationContext().startActivity(myIntent)

;