進行數據傳輸,你可以使用這個庫埃米特
https://github.com/florent37/emmet
我們可以想像一個協議這樣
public interface SmartphoneProtocole{
void getStringPreference(String key);
void getBooleanPreference(String key);
}
public interface WearProtocole{
void onStringPreference(String key, String value);
void onBooleanPreference(String key, boolean value);
}
磨損/ WearActivity.java
//access "MY_STRING" sharedpreference
SmartphoneProtocole smartphoneProtocol = emmet.createSender(SmartphoneProtocole.class);
emmet.createReceiver(WearProtocole.class, new WearProtocole(){
@Override
void onStringPreference(String key, String value){
//use your received preference value
}
@Override
void onBooleanPreference(String key, boolean value){
}
});
smartphoneProtocol.getStringPreference("MY_STRING"); //request the "MY_STRING" sharedpreference
移動/ WearService.java
final WearProtocole wearProtocol = emmet.createSender(WearProtocole.class);
emmet.createReceiver(SmartphoneProtocol.class, new SmartphoneProtocol(){
//on received from wear
@Override
void getStringPreference(String key){
String value = //read the value from sharedpreferences
wearProtocol.onStringPreference(key,value); //send to wear
}
@Override
void getBooleanPreference(String key){
}
});
我期待,而不是學習使用第三方工具。如果我只需要在打開活動時更新磨損應用程序,那麼WearableListenerService不會是一種矯枉過正的行爲? – awonderer