The Internet of Things (IoT) is the network of physical objects or "things" embedded with electronics, software, sensors and connectivity to enable it to achieve greater value and service by exchanging data with the manufacturer, operator and/or other connected devices. Each thing is uniquely identifiable through its embedded computing system but is able to interoperate within the existing Internet infrastructure.
How do you get your piece of an IoT market that by some estimates could be as high as $7.1 trillon in 2020?
Basics of Android Wear and how it works
Android Wear is a version of Google's Android operating system designed for smartwatches and other wearables. By pairing with mobile phones running Android version 4.3+, Android Wear integrates Google Now functionality and mobile notifications into a smartwatch form factor. It also adds the ability to download apps from Google's Play Store.
The platform was announced on March 18, 2014, along with the release of a developer preview. Companies such as Motorola, Samsung, LG, HTC and Asus have been announced as partners. On June 25, 2014, at Google I/O, the Samsung Gear Live and LG G Watch were launched, along with further details about Android Wear. Motorola's Moto 360 was released on September 5, 2014.
Announced Android Wear–based watches include both round and square- or rectangular-shaped watch faces.
Latest version is 5.0.2 (as of 25Apr15). 5.1 (also called Wear 2.0) announced and will be pushed any day.
*Note: Android Wear 5.1 will support Wi-Fi. As long as your watch is connected to a Wi-Fi network, and your phone has a data connection (wherever it is), you’ll be able to get notifications, send messages, and use all your favorite apps. And if you really do forget your phone, you can always ask your watch where it is.
Notifications
Notification notification = new NotificationCompat.Builder(v.getContext()) .setSmallIcon(android.R.drawable.btn_star) .setContentTitle("Hey! Over here...") .setContentText("Hello CodePaLOUsa, this is my Notification!") .build(); NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotifyMgr.notify(1, notification);
NotificationCompat.WearableExtender wearFeatures = new NotificationCompat.WearableExtender(); wearFeatures.setBackground(BitmapFactory.decodeResource(getResources(),R.drawable.red_yum)); wearFeatures.addPages(addPages()); Notification notification = new NotificationCompat.Builder(v.getContext()) .setSmallIcon(android.R.drawable.btn_star) .setContentTitle("Hey! Over here...") .setContentText("Hello CodePaLOUsa, this is my Notification!") .extend(wearFeatures) .addAction(android.R.drawable.ic_menu_set_as,"Open", getDetailIntent(v)) .addAction(android.R.drawable.ic_dialog_map, "Conf", getPendingMapIntent(v, CONF_LOCATION)) .addAction(android.R.drawable.ic_dialog_map, "Yum", getPendingMapIntent(v, YUM_LOCATION)) .setPriority(NotificationCompat.PRIORITY_HIGH) .build(); NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotifyMgr.notify(1, notification);
private ListaddPages(){ List pages = new ArrayList (); for( int i = 1; i <= 2; i++ ){ Notification notification = new NotificationCompat.Builder(this) .setContentTitle("Page " + i) .setContentText("Text for page " + i) .build(); pages.add(notification); } return pages; } private PendingIntent getPendingMapIntent(View v, String location){ Intent mapIntent = new Intent(Intent.ACTION_VIEW); Uri geoUri = Uri.parse("geo:0,0?q=" + Uri.encode(location)); mapIntent.setData(geoUri); PendingIntent mapPendingIntent = PendingIntent.getActivity(v.getContext(), 0, mapIntent, 0); return mapPendingIntent; }
What's involved with creating an app?
Let's do something a bit more substantial. How do you make wear communicate with another device over bluetooth?'
Let's develop a wear application that communicate with your Android phone. To make it more interesting, let's call a ReST service on Compute Engine using the MEAN Stack template.
@Override protected void onCreate(Bundle savedInstanceState) { ... Button sync = (Button) findViewById(R.id.btnSync); sync.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { updateWearable(v.getContext()); sendNotification(v); } }); ... } private void updateWearable(Context context){ googleClient = new GoogleApiClient.Builder(context) .addApi(Wearable.API) .addConnectionCallbacks(MainActivity.this) .addOnConnectionFailedListener(MainActivity.this) .build(); googleClient.connect(); }
public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { ... @Override public void onConnected(Bundle bundle) { Log.d(TAG, "Connected to wear"); mTxtMessage.setText("Connected to wear"); new SendToDataLayerThread("/whos_next_updates", mMessageForDevice).start(); } @Override public void onConnectionSuspended(int i) { Log.d(TAG, "Wear connection suspended"); mTxtMessage.setText("Wear connection suspended"); } @Override public void onConnectionFailed(ConnectionResult connectionResult) { Log.d(TAG, "Unable to connect to device"); mTxtMessage.setText("Unable to connect to device"); } ... }
private class SendToDataLayerThread extends Thread { String path,message; SendToDataLayerThread(String p, String msg) { path = p; message = msg; } public void run() { NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleClient).await(); for (Node node : nodes.getNodes()) { MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage( googleClient, node.getId(), path, message.getBytes()).await(); if (result.getStatus().isSuccess()) { Log.v(TAG, "Message: {" + message + "} sent to: " + node.getDisplayName()); } else { Log.v(TAG, "ERROR: failed to send Message"); } } } }
public class ListenerService extends WearableListenerService { private static final String TAG = "whos_next"; public ListenerService() { } @Override public void onMessageReceived(MessageEvent messageEvent) { if (messageEvent.getPath().equals("/whos_next_updates")) { final String message = new String(messageEvent.getData()); Log.d(TAG, "Message received: " + message); ObjectMapper mapper = new ObjectMapper(); Team team = new Team(); try { team = mapper.readValue(message, Team.class); } catch (IOException e) { e.printStackTrace(); } //set into global state WhosNextApplication app = ((WhosNextApplication) getApplicationContext()); app.setTeam(team); } else { super.onMessageReceived(messageEvent); } } }
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wesleyreisz.whosnext" > <uses-feature android:name="android.hardware.type.watch" /> <application ... <service android:name="com.wesleyreisz.whosnext.Service.ListenerService" android:enabled="true" android:exported="true" > <intent-filter> <action android:name="com.google.android.gms.wearable.BIND_LISTENER" /> </intent-filter> </service> </application> </manifest>
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub); stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { @Override public void onLayoutInflated(WatchViewStub stub) { WhosNextApplication app = ((WhosNextApplication) getApplicationContext()); Team team = app.getTeam(); if (team!=null && team.getSchedule()!=null) { Listschedules = team.getSchedule(); mTextViewOpponent = (TextView) stub.findViewById(R.id.textWhosNextInfo); mTextViewDate = (TextView) stub.findViewById(R.id.textTime); mTextViewLocation = (TextView) stub.findViewById(R.id.textLocation); if (schedules.get(0) != null) { Schedule schedule = schedules.get(0); mTextViewOpponent.setText(schedule.getTeam()); String display = DateUtil.formatDateForDisplay(schedule.getDate()) + " " + schedule.getTime(); mTextViewDate.setText(display); mTextViewLocation.setText(schedule.getLocation()); }else{ mTextViewOpponent.setText("No regular season game found next"); } } } }); }
Wesley Reisz