Android 接收消息SmartYeGlass控制扩展
我想为Sony SmartyeGlass制作一个应用程序,手机上的应用程序和ControlExtension在运行时交换数据 很明显,如何从应用程序向分机发送消息Android 接收消息SmartYeGlass控制扩展,android,messaging,sony,sony-smartwatch,Android,Messaging,Sony,Sony Smartwatch,我想为Sony SmartyeGlass制作一个应用程序,手机上的应用程序和ControlExtension在运行时交换数据 很明显,如何从应用程序向分机发送消息 public void startExtension(String msg) { if (HelloWorldExtensionService.Object != null) { HelloWorldExtensionService.Object .sendMessageToEx
public void startExtension(String msg) {
if (HelloWorldExtensionService.Object != null) {
HelloWorldExtensionService.Object
.sendMessageToExtension(msg);
}
}
但是,如果扩展已经在运行,如何在我的ControlExtension中获取msg
我没有找到类ControlExtension的
onMessageReceived(String message)
方法。您可以使用与标准Android应用程序相同的意图来完成此操作。例如,您的活动:
Intent intentBuzz = new Intent();
intentBuzz.setAction(buzzIntent);
mContext.sendBroadcast(intentBuzz);
然后在控制扩展中注册广播接收器:
buzzReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
buzzAction();
}
};
registerReceiver(buzzReceiver, new IntentFilter(buzzIntent));
如果您想传递字符串以外的内容,也可以通过另一种方式进行传递。您可以使用与标准Android应用程序相同的意图来完成此操作。例如,您的活动:
Intent intentBuzz = new Intent();
intentBuzz.setAction(buzzIntent);
mContext.sendBroadcast(intentBuzz);
然后在控制扩展中注册广播接收器:
buzzReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
buzzAction();
}
};
registerReceiver(buzzReceiver, new IntentFilter(buzzIntent));
如果您希望传递字符串以外的内容,则也可以通过另一种方式进行传递