Android Tutorial

(avery) #1

By : Ketan Bhimani


422 

code demonstrates how to play a sound that is included as a
project resource:

notify.sound = Uri.parse(
"android.resource://com.androidbook.simplenotifications/" +
R.raw.fallbackring);


By default, the audio file is played once. As with the vibration, the
Notification. FLAG_ INSISTENT flag can be used to repeat
incessantly until the user clears the notification. No specific
permissions are needed for this form of notification

Customizing the Notification

Although the default notification behavior in the expanded status
bar tray is sufficient for most purposes, developers can customize
how notifications are displayed if they so choose. To do so,
developers can use the RemoteViews object to customize the look
and feel of a notification.

The following code demonstrates how to create a RemoteViews
object and assign custom text to it:

RemoteViews remote =
new RemoteViews(getPackageName(), R.layout.remote);
remote.setTextViewText(R.id.text1, "Big text here!");
remote.setTextViewText(R.id.text2, "Red text down here!");
notify.contentView = remote;


To better understand this, here is the layout file remote.xml
referenced by the preceding code:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/text1"

Free download pdf