Android how to show notification on screen

前端 未结 5 2123
情歌与酒
情歌与酒 2020-12-05 23:06

I\'ve been working on push notifications and I am able to implement it and display it on status bar, the problem I am facing is that I want to display it even if the phone i

5条回答
  •  心在旅途
    2020-12-05 23:35

    Create Notification using NotificationCompat.Builder

    NotificationCompat.Builder mBuilder =   new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher) // notification icon
                .setContentTitle("Notification!") // title for notification
                .setContentText("Hello word") // message for notification
                .setAutoCancel(true); // clear notification after click
    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
    mBuilder.setContentIntent(pi);
    NotificationManager mNotificationManager =
                        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, mBuilder.build());
    

    Push Notification on locked Screen http://www.hongkiat.com/blog/android-lock-screen-notifications/

提交回复
热议问题