@Override public void onCreate() { super.onCreate(); initGoogleApiClient(); gson = new Gson(); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); }
@Override public void onMessageReceived(MessageEvent messageEvent) { super.onMessageReceived(messageEvent); // Transform byte[] to Bundle byte[] data = messageEvent.getData(); Log.d("listener", messageEvent.getPath()); if (messageEvent.getPath().equals(WearableUtils.STARTED_ROUND)) { if (data.length != 0) { try { NotificationInfo info = WearableUtils.deserializeToInfo(data); showNotification(info); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } } } else if (messageEvent.getPath().equals(WearableUtils.UPDATE_ROUND)) { try { NotificationInfo info = WearableUtils.deserializeToInfo(data); showNotification(info); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } } else if (messageEvent.getPath().equals(WearableUtils.STOPPED_ROUND)) { cancelNotification(); } }
@Override public void onCreate() { super.onCreate(); itemReaderDbHelper = new ItemReaderDbHelper(this); groupReaderDbHelper = new GroupReaderDbHelper(this); }
@Override public void onDestroy() { Log.d(TAG, "onDestroy"); unregisterReceiver(sendMessageReceiver); mGoogleApiClient.disconnect(); Toast.makeText(this, "Flare service stopped", Toast.LENGTH_SHORT).show(); super.onDestroy(); }
@Override public void onMessageReceived(MessageEvent messageEvent) { String new_data = new String(messageEvent.getData(), StandardCharsets.UTF_8); if (messageEvent.getPath().equalsIgnoreCase(IMAGE)) { Log.e("ils", "its here!"); Log.e("the data", new_data); bitmap_string = new_data; } else { super.onMessageReceived(messageEvent); } }
@Override public void onMessageReceived(MessageEvent messageEvent) { if (messageEvent.getPath().equals("/wear")) { final String message = new String(messageEvent.getData()); Log.e("myTag", "Message path received on watch is: " + messageEvent.getPath()); Log.e("myTag", "Message received on watch is: " + message); new GetServerName().execute(); } else { super.onMessageReceived(messageEvent); } }
@Override public void onCreate() { super.onCreate(); Log.d(TAG, "Creating NotificationListener"); mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); prefs = PreferenceManager.getDefaultSharedPreferences(this); registerReceiver(sendMessageReceiver, new IntentFilter(Constants.SEND_MESSAGE_INTENT)); }
@Override public void onCreate() { super.onCreate(); // initialize the googleAPIClient for message passing mApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .addConnectionCallbacks( new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle connectionHint) {} @Override public void onConnectionSuspended(int cause) {} }) .build(); mApiClient.connect(); }
@Override public void onMessageReceived(MessageEvent messageEvent) { if (messageEvent.getPath().equals(PATH_WEATHER_INFO)) { DataMap dataMap = DataMap.fromByteArray(messageEvent.getData()); Bundle bundle = new Bundle(); bundle.putString("minTemp", dataMap.getString("minTemp")); bundle.putString("maxTemp", dataMap.getString("maxTemp")); bundle.putString("weatherId", dataMap.getString("weatherId")); Intent messageIntent = new Intent(); messageIntent.setAction(Intent.ACTION_SEND); messageIntent.putExtras(bundle); LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent); } else { super.onMessageReceived(messageEvent); } }
@Override public void onCreate() { super.onCreate(); googleClient = new GoogleApiClient.Builder(this) .addApiIfAvailable(Wearable.API) .addConnectionCallbacks( new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle bundle) {} @Override public void onConnectionSuspended(int i) {} }) .addOnConnectionFailedListener( new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult connectionResult) {} }) .build(); googleClient.connect(); }
/** * Appellé à la réception d'un message envoyé depuis la montre * * @param messageEvent message reçu */ @Override public void onMessageReceived(MessageEvent messageEvent) { super.onMessageReceived(messageEvent); // Ouvre une connexion vers la montre ConnectionResult connectionResult = mApiClient.blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "Failed to connect to GoogleApiClient."); return; } // traite le message reçu final String path = messageEvent.getPath(); if (path.equals("bonjour")) { // Utilise Retrofit pour réaliser un appel REST AndroidService androidService = new RestAdapter.Builder() .setEndpoint(AndroidService.ENDPOINT) .build() .create(AndroidService.class); // Récupère et deserialise le contenu de mon fichier JSON en objet Element androidService.getElements( new Callback<List<Element>>() { @Override public void success(List<Element> elements, Response response) { envoyerListElements(elements); } @Override public void failure(RetrofitError error) {} }); } }
@Override public void onMessageReceived(MessageEvent messageEvent) { Log.d("T", "in PhoneListenerService, got: " + messageEvent.getPath()); if (messageEvent.getPath().equalsIgnoreCase(TOAST)) { // Value contains the String we sent over in WatchToPhoneService, "good job" String value = new String(messageEvent.getData(), StandardCharsets.UTF_8); // Make a toast with the String Context context = getApplicationContext(); int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, value, duration); toast.show(); // so you may notice this crashes the phone because it's // ''sending message to a Handler on a dead thread''... that's okay. but don't do this. // replace sending a toast with, like, starting a new activity or something. // who said skeleton code is untouchable? #breakCSconceptions } else { super.onMessageReceived(messageEvent); } }
@Override public void onCreate() { super.onCreate(); }
@Override public void onDestroy() { super.onDestroy(); mApiClient.disconnect(); }
@Override public void onCreate() { super.onCreate(); mApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build(); mApiClient.connect(); }
@Override public void onDestroy() { super.onDestroy(); }