Customize Notification Area in Android -



Customize Notification Area in Android -

i using remoteviews create custom notification. there way customize notification area specially height...??? don't want utilize bigview coz need utilize apis less 11.

the sanpshots :

here code :

public class main extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.notificationmain); button bnotify = (button) findviewbyid(r.id.notification); button bcustomnotify = (button) findviewbyid(r.id.customnotification); // click default notification bnotify.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { notification(); } }); // click custom notification bcustomnotify.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { customnotification(); } }); } // default notification public void notification() { string strtitle = getstring(r.string.notificationtitle); string strtext = getstring(r.string.notificationtext); intent intent = new intent(this, notificationview.class); intent.putextra("title", strtitle); intent.putextra("text", strtext); pendingintent pintent = pendingintent.getactivity(this, 0, intent, pendingintent.flag_update_current); notificationcompat.builder builder = new notificationcompat.builder(this) .setsmallicon(r.drawable.logosmall) .setticker(getstring(r.string.notificationticker)) .setcontenttitle(getstring(r.string.notificationtitle)) .setcontenttext(getstring(r.string.notificationtext)) .addaction(r.drawable.ic_launcher, "action button", pintent) .setcontentintent(pintent) .setautocancel(true); // create notification manager notificationmanager notificationmanager = (notificationmanager) getsystemservice(notification_service); notificationmanager.notify(0, builder.build()); } // custom notification public void customnotification() { // using remoteviews bind custom layouts notification remoteviews remoteviews = new remoteviews(getpackagename(), r.layout.customnotification); string strtitle = getstring(r.string.customnotificationtitle); string strtext = getstring(r.string.customnotificationtext); intent intent = new intent(this, notificationview.class); intent.putextra("title", strtitle); intent.putextra("text", strtext); pendingintent pintent = pendingintent.getactivity(this, 0, intent, pendingintent.flag_update_current); notificationcompat.builder builder = new notificationcompat.builder(this) .setsmallicon(r.drawable.logosmall) .setticker(getstring(r.string.customnotificationticker)) .setautocancel(true) .setcontentintent(pintent) .setcontent(remoteviews); remoteviews.setimageviewresource(r.id.imagenotileft,r.drawable.ic_launcher); remoteviews.setimageviewresource(r.id.imagenotiright,r.drawable.androidhappy); remoteviews.settextviewtext(r.id.title,getstring(r.string.customnotificationtitle)); remoteviews.settextviewtext(r.id.text,getstring(r.string.customnotificationtext)); calendar cal = calendar.getinstance(); cal.gettime(); simpledateformat sdf = new simpledateformat("hh:mm a"); remoteviews.settextviewtext(r.id.time,sdf.format(cal.gettime()) ); notificationmanager notificationmanager = (notificationmanager) getsystemservice(notification_service); notificationmanager.notify(1, builder.build()); } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.activity_main, menu); homecoming true; } }

it looks android back upwards library v4 has notification builder supports sort of thing: http://developer.android.com/reference/android/support/v4/app/notificationcompat.inboxstyle.html

notificationcompat.inboxstyle appears bigview equivalent pre-4.1 devices.

this allows create larger notification 5 lines of text, may suit needs.

notification noti = new notification.builder() .setcontenttitle("5 new mails " + sender.tostring()) .setcontenttext(subject) .setsmallicon(r.drawable.new_mail) .setlargeicon(abitmap) .setstyle(new notification.inboxstyle() .addline(str1) .addline(str2) .setcontenttitle("") .setsummarytext("+3 more")) .build();

here's short tutorial: http://doandroidcoding.blogspot.com/2014/01/bigview-style-notification.html?m=1

android android-notifications android-notification-bar android-remoteview

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -