我正在尝试通知告诉我我的CountDownTimer
已经结束,但我遇到了一些麻烦。目前我已经建立了一个测试通知(我认为)但我不知道如何调用通知工作。这就是我现在所拥有的:
public void onFinish() {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(TestTimer.this);
mBuilder.setContentTitle("Notification Alert, Click Me!");
mBuilder.setContentText("Hi, This is Android Notification Detail!");
TextView timer=(TextView)findViewById(R.id.mTextField);
timer.setText("Seconds remaining: 0 ")
一旦计时器= 0,就会调用它,我想知道是否有可能在通知时调用通知。
预先感谢您提供任何帮助,如果您需要更多代码,请随时提出。
答案 0 :(得分:5)
要启用通知,您需要致电PendingIntent
,以便通知正常。
在onFinish
public void onFinish() {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification myNotification = new Notification(R.drawable.ic_launcher, "Notification!", System.currentTimeMillis());
Context context = getApplicationContext();
String notificationTitle = "Exercise of Notification!";
String notificationText = "http://android-er.blogspot.com/";
Intent myIntent = new Intent(MainActivity.this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, myIntent, Intent.FILL_IN_ACTION);
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.setLatestEventInfo(context, notificationTitle, notificationText, pendingIntent);
notificationManager.notify(1, myNotification);
}