我想通过在智能手表上做一些震动来确认我在智能手机上所做的操作(例如,发送电子邮件时)。
在我的MainActivity中(发送电子邮件时),我有:
Intent serviceIntent = new Intent(this, HelloExtensionService.class);
serviceIntent.setAction(HelloExtensionService.INTENT_ACTION_SEND);
startService(serviceIntent);我通过一个例子了解到,我必须在扩展ExtensionService的类中重写onStartCommand:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Intent i = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
i.setPackage("com.example.hellosmartwatch");
sendBroadcast(i);
}
@Override
public ControlExtension createControlExtension(String hostAppPackageName) {
boolean advancedFeaturesSupported = DeviceInfoHelper.isSmartWatch2ApiAndScreenDetected(this, hostAppPackageName);
if (advancedFeaturesSupported) {
return new Vibrator(this,hostAppPackageName, new Handler());
} else {
return null;
}
}我知道我必须使用ControlExtension,在我的例子中是Vibrator.class,所以我覆盖了onStart()方法:
@Override
public void onStart() {
startVibrator(500, 300, 2);
}但它不起作用。我错过的或者我不理解的东西都可以工作。
发布于 2014-07-08 06:43:58
我想知道您是否想要使用通知扩展而不是控制扩展。这将为您震动手表,并快速跟踪记录以前的事件。如果您需要此类扩展的示例,我会推荐Sony Add-On SDK中的HelloNotification示例。否则,如果您使用控制扩展,您将不得不在SmartWatch上启动应用程序,运行振动命令,然后停止应用程序。这听起来像是对你有用吗?
https://stackoverflow.com/questions/24556544
复制相似问题