Android Tutorial

(avery) #1

By : Ketan Bhimani


418 

Setting the Notification.FLAG_AUTO_CANCEL flag causes
notifications to be canceled when the user clicks on them. This is
convenient and easy for the application when just launching the
Intent is good enough.

The Notification object is a little different from other Android
objects you might have encountered. Most of the interaction with it
is through direct access to its public variables instead of through
helper methods. This is useful for a background application or
service, discussed in Chapter “Working with Services.”The
Notification object can be kept around and only the values that
need to be changed can be modified. After any change, the
Notification needs to be posted again by calling the notify()
method.

Vibrating the Phone

Vibration is a great way to enable notifications to catch the
attention of a user in noisy environments or alert the user when
visible and audible alerts are not appropriate (though a vibrating
phone is often noisy on a hard desktop surface).Android
notifications give a fine level of control over how vibration is
performed. However, before the application can use vibration with
a notification, an explicit permission is needed. The following XML
within your application’s AndroidManifest.xml file is required to use
vibration:

<uses-permission
android:name="android.permission.VIBRATE" />


Without this permission, the vibrate functionality will not work nor
will there be any error. With this permission enabled, the
application is free to vibrate the phone however it wants. This is
Free download pdf