Android Notification Manager

端木阳荣
2023-12-01

private NotificationManager Noti;

 

public void onCreate() {

 ....

   //add Notification Massage
        Noti = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

....

 

showNotification(R.drawable.start, "start");

 

}

 

 

private void showNotification(int iconId, String text) {
        Intent notifyIntent = new Intent(this, RemoteService.class);
        notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        PendingIntent appIntent = PendingIntent.getActivity(RemoteService.this, 0,
                notifyIntent, 0);


        Notification myNoti = new Notification();
        myNoti.icon = iconId;
        myNoti.tickerText = text;
        myNoti.defaults = Notification.DEFAULT_SOUND;
        myNoti.setLatestEventInfo(RemoteService.this, "Usb2Net", text, appIntent);

        Noti.notify(0, myNoti);
    }

 类似资料:

相关阅读

相关文章

相关问答