CHAPTER 5 ■ IOT PATTERNS: REALTIME CLIENTS
// The stack builder object will contain an artificial back
// stack for the started Activity. This ensures that navigating
// backward from the Activity leads out of your application to the
// Home screen.
TaskStackBuilder stackBuilder =
TaskStackBuilder.create(getApplicationContext());
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(100, mBuilder.build());
}
}
Finally, you need to update AndroidManifest.xml under the App ➤ Manifests folder.
Your app uses MqttService in the backend, so you need to add a reference to the service.
Your app also needs to access the Internet for connecting to the MQTT broker, so add the
Internet permissions in AndroidManifest.xml as well. Listing 5-20 provides the code that
needs to be added to AndroidManifest.xml.
Listing 5-20. Add App Permissions in AndroidManifest.xml