本文整理汇总了Java中com.google.android.gms.wearable.MessageEvent类的典型用法代码示例。如果您正苦于以下问题:Java MessageEvent类的具体用法?Java MessageEvent怎么用?Java MessageEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageEvent类属于com.google.android.gms.wearable包,在下文中一共展示了MessageEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/heartRate")) {
final String message = new String(messageEvent.getData());
Log.v("pactchat", "Message path received on watch is: " + messageEvent.getPath());
Log.v("packtchat", "Message received on watch is: " + message);
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("heart", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
}
else {
super.onMessageReceived(messageEvent);
}
}
示例2: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/stepcount")) {
final String message = new String(messageEvent.getData());
Log.v("pactchat", "Message path received on watch is: " + messageEvent.getPath());
Log.v("packtchat", "Message received on watch is: " + message);
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
}
else {
super.onMessageReceived(messageEvent);
}
}
示例3: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/message_path")) {
final String message = new String(messageEvent.getData());
Log.v("myTag", "Message path received on watch is: " + messageEvent.getPath());
Log.v("myTag", "Message received on watch is: " + message);
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
}
else {
super.onMessageReceived(messageEvent);
}
}
示例4: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/from-wear")) {
final String message = new String(messageEvent.getData());
Log.v("pactchat", "Message path received on watch is: " + messageEvent.getPath());
Log.v("packtchat", "Message received on watch is: " + message);
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
}
else {
super.onMessageReceived(messageEvent);
}
}
示例5: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/stepcount")) {
final String message = new String(messageEvent.getData());
Log.v(TAG, "Message path received from wear is: " + messageEvent.getPath());
Log.v(TAG, "Message received on watch is: " + message);
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
}
else {
super.onMessageReceived(messageEvent);
}
}
示例6: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
/**
* Handle messages from the phone
* @param messageEvent new message from the phone
*/
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/start")) {
dataManager.turnSensorOn(Integer.valueOf(new String(messageEvent.getData())));
}
else if (messageEvent.getPath().equals("/stop")){
dataManager.turnSensorOff(Integer.valueOf(new String(messageEvent.getData())));
}
else if (messageEvent.getPath().equals("/stopAll")){
dataManager.turnAllSensorsOff();
}
else if (messageEvent.getPath().equals("/ping")){
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(apiClient).await();
for(Node node : nodes.getNodes()) {
Wearable.MessageApi.sendMessage(apiClient, node.getId(), "/connected", null).await();
}
}
}
开发者ID:ibm-wearables-sdk-for-mobile,项目名称:ibm-wearables-android-sdk,代码行数:27,代码来源:MessageReceiverService.java
示例7: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent)
{
super.onMessageReceived(messageEvent);
if (messageEvent.getPath().equals(START_ACTIVITY_PATH))
{
Intent intent = new Intent(this, SpaceRemoteActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
long[] vibrationPattern = {0, 75, 50, 75};
vibrator.vibrate(vibrationPattern, -1);
}
}
示例8: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
//This method will call while any message is posted by the watch to the phone.
//This is message api, so if the phone is not connected message will be lost.
//No guarantee of the message delivery
//check path of the message
if (messageEvent.getPath().equalsIgnoreCase(STEP_COUNT_MESSAGES_PATH)) {
//Extract the values
String stepCount = new String(messageEvent.getData());
Log.d("Step count: ", stepCount + " ");
//send broadcast to update the UI in MainActivity based on the tracking status
Intent intent = new Intent(TRACKING_COUNT_ACTION);
intent.putExtra("step-count", stepCount);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
} else {
super.onMessageReceived(messageEvent);
}
}
示例9: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
super.onMessageReceived(messageEvent);
Log.d("WEAR", "Message received: " + messageEvent);
nodeId = messageEvent.getSourceNodeId();
//Toast.makeText(this, "Command received", Toast.LENGTH_LONG).show();
if (messageEvent.getPath().contains(LAST_KNOW_GPS_POSITION)) {
new Thread(){
@Override
public void run() {
super.run();
try {
LocationManager locationManager = (LocationManager) WatchFaceWearableListenerService.this.getSystemService(Context.LOCATION_SERVICE);
String locationProvider = LocationManager.NETWORK_PROVIDER;
// Or use LocationManager.GPS_PROVIDER
Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);
if(lastKnownLocation != null) {
reply(LAST_KNOW_GPS_POSITION, lastKnownLocation.getLatitude() + "_" + lastKnownLocation.getLongitude());
}
}catch (Exception e){e.printStackTrace();}
}
}.start();
}
}
示例10: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
String message = new String(messageEvent.getData());
if (messageEvent.getPath().equals(Constants.MYCROFT_QUERY_MESSAGE_PATH)) {
Log.d(TAG, "MycroftWearRequest Message: " + message);
Intent startIntent = new Intent(this, MainActivity.class);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startIntent.putExtra("MYCROFT_WEAR_REQUEST", message);
startActivity(startIntent);
handoffWearRequest(message);
}
}
示例11: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent){
if( messageEvent.getPath().equalsIgnoreCase( "/saw_repl" ) ) {
//String msg = messageEvent.getData();
Log.i("DEV", "Got queue sent confirmation!");
}
else if (messageEvent.getPath().equalsIgnoreCase(SEND_UPDATE_REQUEST)){
try {
sendQueueToWear(mQueue);
} catch (JSONException e) {
e.printStackTrace();
}
}
else if (messageEvent.getPath().equalsIgnoreCase(SEND_KICK_USER)){
kickUser(messageEvent.getData());
}
else if (messageEvent.getPath().equalsIgnoreCase(SEND_ATTEND_USER)){
attendUser(messageEvent.getData());
} else {
super.onMessageReceived( messageEvent );
}
}
示例12: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
super.onMessageReceived(messageEvent);
if (messageEvent.getPath().equals("/BatteryLevel")) {
String s = new String(messageEvent.getData());
Log.d(this.getClass().getSimpleName(), "受信したバッテリーレベル = " + s);
MyWearApplication app = (MyWearApplication) getApplication();
try {
app.setBatteryLevel(Integer.parseInt(s));
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
示例13: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
super.onMessageReceived(messageEvent);
String path = messageEvent.getPath();
switch (path) {
case "/RequestBatteryLevel":
Log.d(sTag, "バッテリーレベル要求を受信");
mApiClient = new GoogleApiClient.Builder(
getApplicationContext(), mConnectionCallback, mConnFailedCallback)
.addApi(Wearable.API)
.build();
mApiClient.connect();
break;
}
}
示例14: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(final MessageEvent messageEvent) {
super.onMessageReceived(messageEvent);
switch (messageEvent.getPath()) {
case DataPaths.Messages.SEARCH_RESULT:
WearSearchData.Results searchResults = null;
final byte[] data = messageEvent.getData();
if (data != null && data.length != 0) {
try {
searchResults = WearSearchData.Results.parseFrom(data);
} catch (InvalidProtocolBufferNanoException e) {
Log.w(TAG, e);
}
}
if (searchResults == null) {
searchResults = new WearSearchData.Results();
}
EventBus.getDefault().post(new EventSearchResults(searchResults));
break;
}
}
示例15: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
// Guard Clauses
if (knownMessagePathList == null || knownMessagePathList.isEmpty()) {
Log.e(getClass().getSimpleName(), "KnownMessagePathList is empty/null");
return;
}
else if (messageEvent == null || messageEvent.getPath() == null) {
Log.e(getClass().getSimpleName(), "MessageEvent or its path is null");
return;
}
for (String knownMessagePath : knownMessagePathList) {
if (messageEvent.getPath().equals(knownMessagePath)) {
// Try to send a local broadcast, if it fails, send an intent
if (canSendEventBusMessage()) {
EventBus.getDefault().post(new WearExchangeMessageEvent(messageEvent));
} else {
sendIntentMessage(messageEvent);
}
break;
}
}
}