简体   繁体   English

Android-未出现通知

[英]Android - Notification isn't appeared

I'm trying to create Notification using AppCompat inside Fragment. 我正在尝试在Fragment中使用AppCompat创建通知。 I create see nothing. 我创造什么都看不到。

Code: 码:

private void createNotification()
{
    Context context = getActivity().getApplicationContext();
    Intent notificationIntent = new Intent(context, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentIntent(contentIntent)
            .setSmallIcon(R.drawable.ymk_ya_logo)
            .setAutoCancel(false)
            .setContentTitle("notify")
            .setContentText("test");

    Notification notification = builder.build();

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.notify(777, notification);
}

Try changing your last bit to this instead: 尝试将您的最后一位更改为:

NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0, builder.build());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM