Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this a stock Android Notification (RemoteView) layout?

On my HTC phone the RemoteView for notifications looks like the image below...

enter image description here

I'd like to use the same layout (image, bold text and small text) for a notification in my app but I can't work out if it's a stock Android layout or not. I've created my own layout but it's not quite the same and I'd like to stick to the 'standard' if possible.

Using eclipse I tried typing in android.R.layout. to see what the suggestions were but I can't see any with a name which would suggest a notification layout.

Is it a stock Android layout? If so, how do I access it?

like image 860
Squonk Avatar asked May 09 '12 00:05

Squonk


1 Answers

It is standard Android notification layout and you don't need to create your own custom layout. Just use existing notification API to set drawable, title and text. Below is an example, using NotificationCompat.Builder from compatibility library:

Intent notificationIntent = new Intent(this, ActivityHome.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentIntent(pendingIntent)
        .setWhen(System.currentTimeMillis())
        .setTicker(getText(R.string.notification_ticker))
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle(getText(R.string.notification_title))
        .setContentText(getText(R.string.notification_text));

mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification());

And the same using Notification class:

Notification notification = new Notification(R.drawable.notification_icon, getText(R.string.notification_ticker), System.currentTimeMillis());

Intent notificationIntent = new Intent(this, ActivityHome.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

notification.setLatestEventInfo(this, getString(R.string.notification_title), getText(R.string.notification_text), pendingIntent);

mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification());
like image 88
StenaviN Avatar answered Sep 22 '22 18:09

StenaviN