java - How can I set time and date for notification in second time? -


.setwhen(system.currenttimemillis())  

is code set time in push notification android , result 15.54. if want set time 15:54:02 seconds time should do? can me or provide me example source code?

this notification-manager source code.

    notificationcompat.builder mbuilder = new notificationcompat.builder(mctx);     notification notification;     notification = mbuilder.setsmallicon(r.drawable.logo).setticker(title).setwhen(0)             .setautocancel(true)             .setcontentintent(resultpendingintent)             .setcontenttitle(title)             .setsmallicon(r.drawable.logo)             .setwhen(system.currenttimemillis())             .setlargeicon(bitmapfactory.decoderesource(mctx.getresources(), r.mipmap.ic_launcher))             .setcontenttext(message)             .build();      notification.flags |= notification.flag_auto_cancel;     notification.flags |= notification.flag_show_lights;      notification.defaults = notification.default_sound;     notification.defaults |= notification.default_vibrate;     notification.defaults = notification.default_all;     int id = (int) system.currenttimemillis();     notificationmanager notificationmanager = (notificationmanager) mctx.getsystemservice(context.notification_service);     notificationmanager.notify(id_small_notification, notification);     notificationmanager.notify(id, notification); } 

you set or not millisecond .setwhen() default that.

time format want show 15:54:02 24 hour format second. there no settings time format notificationcompat.builder class.

what ever set millisecond convert time show in notification 15:54 without second.

what can use custom notification view rather default view.

    simpledateformat sdf = new simpledateformat("hh:mm:ss");     string formatteddate = "";     formatteddate = sdf.format(new date());      remoteviews contentview = new remoteviews(getpackagename(), r.layout.notification);     contentview.setimageviewresource(r.id.image, r.drawable.logo);     contentview.settextviewtext(r.id.title, title);     contentview.settextviewtext(r.id.text, message);     contentview.settextviewtext(r.id.time, formatteddate);      notificationcompat.builder mbuilder = new notificationcompat.builder(this)             .setsmallicon(r.drawable.home)             .setcontent(contentview);      notification notification = mbuilder.build();     notification.flags |= notification.flag_auto_cancel;     notification.defaults |= notification.default_sound;     notification.defaults |= notification.default_vibrate;     notificationmanager notificationmanager = (notificationmanager) mainactivity.this.getsystemservice(context.notification_service);     int id = (int) system.currenttimemillis();     notificationmanager.notify(id, notification); 

layout..

<?xml version="1.0" encoding="utf-8"?> <linearlayout  xmlns:android="http://schemas.android.com/apk/res/android"           android:layout_width="match_parent"           android:layout_height="match_parent"           android:orientation="horizontal"           android:gravity="left|center_horizontal|center_vertical"           android:weightsum="4">  <relativelayout       android:id="@+id/layout"       android:layout_width="0dp"       android:layout_weight="3"       android:layout_height="64dp"       android:padding="10dp" >     <imageview         android:src="@mipmap/ic_launcher"         android:id="@+id/image"         android:layout_width="wrap_content"         android:layout_height="fill_parent"         android:layout_alignparentleft="true"         android:layout_marginright="10dp" />     <textview         android:textsize="13dp"         android:textcolor="#000"         android:text="testing"         android:id="@+id/title"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_torightof="@id/image"         />     <textview         android:textsize="13dp"         android:textcolor="#000"         android:text="testing awecome"         android:id="@+id/text"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_torightof="@id/image"         android:layout_below="@id/title"         /> </relativelayout>  <textview     android:textsize="13dp"     android:textcolor="#000"     android:text="testing"     android:id="@+id/time"     android:layout_width="0dp"     android:layout_weight="1"     android:paddingright="20dp"     android:gravity="right|center_vertical|center_horizontal"     android:layout_height="wrap_content"     android:layout_torightof="@id/image"/>    </linearlayout> 

output ...

enter image description here


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -