Listing 922 Applying a custom layout to the Notification status window

Available for download on Wrox.com

Notification notification = new Notification(R.drawable.icon,

"Custom Content", System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;

notification.contentView = new RemoteViews(this.getPackageName(), R.layout.my_status_window_layout);

Intent intent = new Intent(this, MyActivity.class); PendingIntent.getActivity(this, 0, intent, 0)); notification.contentlntent = pendinglntent;

Note that when you manually set the contentview property you must also set the contentintent or an exception will be thrown when the notification is triggered.

Remote Views are a mechanism that enables you to embed and control a layout embedded within a separate application, most commonly when creating home screen widgets. There are strict limits on the Views you can use when creating a layout to be used for a Remote View. These are covered in some detail in the next chapter.

To modify the properties and appearance of the Views used in your status window layout, use the set* methods on the Remote View object, as shown in Listing 9-23, which modifies each of the Views used in the layout defined in Listing 9-21.

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Post a comment