我构建了一个对话框,用于显示和推送通知,但无法显示
builder.setPositiveButton("Later", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//----------------------------//
NotificationCompat.Builder mNotification = new NotificationCompat.Builder(ProfileNavigationDrawer.this);
mNotification.setSmallIcon(R.drawable.start);
mNotification.setTicker("Trip Name");
mNotification.setContentTitle("Click to Start your Trip");
mNotification.setContentText("Click to Appear");
mNotification.setDefaults(Notification.DEFAULT_VIBRATE);
Toast.makeText(ProfileNavigationDrawer.this, "Later Clicked ", Toast.LENGTH_SHORT).show();
}
});
答案 0 :(得分:0)
您的最终代码
builder.setPositiveButton("Later", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
NotificationCompat.Builder mNotification = new NotificationCompat.Builder(ProfileNavigationDrawer.this);
mNotification.setSmallIcon(R.drawable.start);
mNotification.setTicker("Trip Name");
mNotification.setContentTitle("Click to Start your Trip");
mNotification.setContentText("Click to Appear");
mNotification.setDefaults(Notification.DEFAULT_VIBRATE);
Toast.makeText(ProfileNavigationDrawer.this, "Later Clicked ", Toast.LENGTH_SHORT).show();
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, mNotification.build());
}
});