Teh*_*ohn 0 notifications android
我正在尝试通知告诉我,我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 ")
Run Code Online (Sandbox Code Playgroud)
一旦timer = 0就调用它,我想知道是否可以在它发出通知时调用它.
在此先感谢您的帮助,如果您需要更多代码,请随时提出.
要启用通知,您需要拨打电话,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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
761 次 |
| 最近记录: |