use of com.google.android.gms.wearable.Node in project Talon-for-Twitter by klinker24.
the class WearableUtils method getNodes.
public HashSet<String> getNodes(GoogleApiClient apiClient) {
final HashSet<String> results = new HashSet<String>();
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(apiClient).await();
for (Node node : nodes.getNodes()) {
results.add(node.getId());
}
return results;
}
use of com.google.android.gms.wearable.Node in project ETSMobile-Android2 by ApplETS.
the class Utils method getRemoteNodeId.
public static String getRemoteNodeId(GoogleApiClient googleApiClient) {
NodeApi.GetConnectedNodesResult nodesResult = Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
List<Node> nodes = nodesResult.getNodes();
for (Node node : nodes) {
if (node.isNearby()) {
return node.getId();
}
}
if (nodes.size() > 0) {
return nodes.get(0).getId();
}
return null;
}
use of com.google.android.gms.wearable.Node in project muzei by romannurik.
the class ActivateMuzeiIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String action = intent.getAction();
if (TextUtils.equals(action, ACTION_MARK_NOTIFICATION_READ)) {
preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
return;
} else if (TextUtils.equals(action, ACTION_REMOTE_INSTALL_MUZEI)) {
Intent remoteIntent = new Intent(Intent.ACTION_VIEW).addCategory(Intent.CATEGORY_BROWSABLE).setData(Uri.parse("market://details?id=" + getPackageName()));
RemoteIntent.startRemoteActivity(this, remoteIntent, new ResultReceiver(new Handler()) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
if (resultCode == RemoteIntent.RESULT_OK) {
FirebaseAnalytics.getInstance(ActivateMuzeiIntentService.this).logEvent("activate_notif_install_sent", null);
preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
} else {
Toast.makeText(ActivateMuzeiIntentService.this, R.string.activate_install_failed, Toast.LENGTH_SHORT).show();
}
}
});
return;
}
// else -> Open on Phone action
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
Log.e(TAG, "Failed to connect to GoogleApiClient.");
Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show();
return;
}
Set<Node> nodes = Wearable.CapabilityApi.getCapability(googleApiClient, "activate_muzei", CapabilityApi.FILTER_REACHABLE).await().getCapability().getNodes();
if (nodes.isEmpty()) {
Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show();
} else {
FirebaseAnalytics.getInstance(this).logEvent("activate_notif_message_sent", null);
// Show the open on phone animation
Intent openOnPhoneIntent = new Intent(this, ConfirmationActivity.class);
openOnPhoneIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
openOnPhoneIntent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.OPEN_ON_PHONE_ANIMATION);
startActivity(openOnPhoneIntent);
// Clear the notification
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(INSTALL_NOTIFICATION_ID);
preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
// Send the message to the phone to open Muzei
for (Node node : nodes) {
Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), "notification/open", null).await();
}
}
googleApiClient.disconnect();
}
use of com.google.android.gms.wearable.Node in project muzei by romannurik.
the class ActivateMuzeiIntentService method maybeShowActivateMuzeiNotification.
public static void maybeShowActivateMuzeiNotification(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (preferences.getBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, false)) {
return;
}
NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
StatusBarNotification[] notifications = notificationManager.getActiveNotifications();
boolean hasInstallNotification = false;
boolean hasActivateNotification = false;
for (StatusBarNotification notification : notifications) {
if (notification.getId() == INSTALL_NOTIFICATION_ID) {
hasInstallNotification = true;
} else if (notification.getId() == ACTIVATE_NOTIFICATION_ID) {
hasActivateNotification = true;
}
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.drawable.ic_stat_muzei).setColor(ContextCompat.getColor(context, R.color.notification)).setPriority(NotificationCompat.PRIORITY_MAX).setDefaults(NotificationCompat.DEFAULT_VIBRATE).setAutoCancel(true).setContentTitle(context.getString(R.string.activate_title));
Intent deleteIntent = new Intent(context, ActivateMuzeiIntentService.class);
deleteIntent.setAction(ACTION_MARK_NOTIFICATION_READ);
builder.setDeleteIntent(PendingIntent.getService(context, 0, deleteIntent, 0));
// Check if the Muzei main app is installed
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context).addApi(Wearable.API).build();
ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
Set<Node> nodes = new TreeSet<>();
if (connectionResult.isSuccess()) {
nodes = Wearable.CapabilityApi.getCapability(googleApiClient, "activate_muzei", CapabilityApi.FILTER_ALL).await().getCapability().getNodes();
googleApiClient.disconnect();
}
if (nodes.isEmpty()) {
if (hasInstallNotification) {
// No need to repost the notification
return;
}
// Send an install Muzei notification
if (PlayStoreAvailability.getPlayStoreAvailabilityOnPhone(context) != PlayStoreAvailability.PLAY_STORE_ON_PHONE_AVAILABLE) {
builder.setContentText(context.getString(R.string.activate_no_play_store));
FirebaseAnalytics.getInstance(context).logEvent("activate_notif_no_play_store", null);
} else {
builder.setContentText(context.getString(R.string.activate_install_muzei));
Intent installMuzeiIntent = new Intent(context, ActivateMuzeiIntentService.class);
installMuzeiIntent.setAction(ACTION_REMOTE_INSTALL_MUZEI);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, installMuzeiIntent, 0);
builder.addAction(new NotificationCompat.Action.Builder(R.drawable.open_on_phone, context.getString(R.string.activate_install_action), pendingIntent).extend(new NotificationCompat.Action.WearableExtender().setHintDisplayActionInline(true).setAvailableOffline(false)).build());
builder.extend(new NotificationCompat.WearableExtender().setContentAction(0));
FirebaseAnalytics.getInstance(context).logEvent("activate_notif_play_store", null);
}
notificationManager.notify(INSTALL_NOTIFICATION_ID, builder.build());
return;
}
// else, Muzei is installed on the phone/tablet, but not activated
if (hasInstallNotification) {
// Clear any install Muzei notification
notificationManager.cancel(INSTALL_NOTIFICATION_ID);
}
if (hasActivateNotification) {
// No need to repost the notification
return;
}
String nodeName = nodes.iterator().next().getDisplayName();
builder.setContentText(context.getString(R.string.activate_enable_muzei, nodeName));
Intent launchMuzeiIntent = new Intent(context, ActivateMuzeiIntentService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, launchMuzeiIntent, 0);
builder.addAction(new NotificationCompat.Action.Builder(R.drawable.open_on_phone, context.getString(R.string.activate_action, nodeName), pendingIntent).extend(new NotificationCompat.Action.WearableExtender().setHintDisplayActionInline(true).setAvailableOffline(false)).build());
Bitmap background = null;
try {
background = BitmapFactory.decodeStream(context.getAssets().open("starrynight.jpg"));
} catch (IOException e) {
Log.e(TAG, "Error reading default background asset", e);
}
builder.extend(new NotificationCompat.WearableExtender().setContentAction(0).setBackground(background));
FirebaseAnalytics.getInstance(context).logEvent("activate_notif_installed", null);
notificationManager.notify(ACTIVATE_NOTIFICATION_ID, builder.build());
}
Aggregations