我无法推送通知?用这个代码?

时间:2017-02-18 12:32:01

标签: android android-layout android-studio push-notification

我构建了一个对话框,用于显示和推送通知,但无法显示

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();


    }
});

1 个答案:

答案 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());



}
});