Create custom notification, android -
i want create notification red bordered notification in image:
i know how create normal notifications blue bordered notifications in image, want show icon , 3 lines of information near that. how can that? suggestion appreciated.
add remoteview in notification here sample
remoteviews remoteviews = new remoteviews(getpackagename(), r.layout.widget); notificationcompat.builder mbuilder = new notificationcompat.builder( this).setsmallicon(r.drawable.ic_launcher).setcontent( remoteviews); // creates explicit intent activity in app intent resultintent = new intent(this, test.class); // stack builder object contain artificial stack // // started activity. // ensures navigating backward activity leads out of // application home screen. taskstackbuilder stackbuilder = taskstackbuilder.create(this); // adds stack intent (but not intent itself) stackbuilder.addparentstack(test.class); // adds intent starts activity top of stack stackbuilder.addnextintent(resultintent); pendingintent resultpendingintent = stackbuilder.getpendingintent(0, pendingintent.flag_update_current); remoteviews.setonclickpendingintent(r.id.button1, resultpendingintent); notificationmanager mnotificationmanager = (notificationmanager) getsystemservice(context.notification_service); // mid allows update notification later on. mnotificationmanager.notify(100, mbuilder.build());
widget.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="horizontal" > <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="dj notification" android:textappearance="?android:attr/textappearancemedium" /> <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="close me" /> </linearlayout>
check article there more style avaialbe
edited:
the notificationcompat.builder easy way create notifications on android versions. can use features available android 4.1. if app runs on devices android >=4.1 new features used, if run on android <4.1 notification simple old notification.
for < 11 api use http://www.framentos.com/en/android-tutorial/2012/02/20/how-to-create-a-custom-notification-on-android/
Comments
Post a Comment