android - Android 通知中的错误时间戳

标签 android notifications timestamp

在我的标准 Android 通知的右下角,我不会看到时间(例如 12:00),而是这样的模式:11/1/16。总是 3 个数字减去“/”。有人知道这个问题吗?

最佳答案

我不知道你是如何发出通知的,但我认为你应该使用:System.currentTimeMillis()

示例:

package com.test;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;

public class TestActivity extends Activity {

    private NotificationManager notificationManager;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        showNotification("My notification",android.R.id.text1);
    }

    private void showNotification(CharSequence text, int idNotify) {
      Notification notification = new Notification(R.drawable.icon, text, System.currentTimeMillis());
      Intent intent = new Intent();
      intent.setClassName("com.test","com.test.TestActivity");
      PendingIntent contentIntent = PendingIntent.getActivity(TestActivity.this, 0,intent,0);
      notification.setLatestEventInfo(this, "My Notification",text, contentIntent);
      notification.flags |= Notification.FLAG_AUTO_CANCEL;
      notificationManager.notify(idNotify, notification);
    }
}

关于android - Android 通知中的错误时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8567541/

相关文章:

android - Recyclerview 在滚动完成之前不能顺利滚动

java - 如何在ConstraintLayout中将ImageView放在CardView之上

java - touchlistener 代码错误 - Android

java - 域对象的更改通知(Hibernate/Java)

java - 如何从纪元微秒或纳秒创建 Java Instant?

java - 无法执行 android :on remind me 的方法

ios - 从通知中删除声音

android - 单击通知栏时复制应用程序

java - 如何检索 .jar 时间戳?

mysql - SQL查询按时间戳的月份部分分组