How to create Custom Notification in android

后端 未结 4 1199
庸人自扰
庸人自扰 2021-02-10 04:51

I need to create a custom notification instead of the default notification in android. Current notification have a icon,heading and message like below image

4条回答
  •  清歌不尽
    2021-02-10 05:21

    you can use NotificationCompat that need remoteview . below i set my custom layout named
    activity_downlaodactivity

    NotificationManager manager =   (NotificationManager)       getSystemService(Context.NOTIFICATION_SERVICE);
        RemoteViews contentView = new RemoteViews(getPackageName(),R.layout.activity_downlaodactivity);
    
    
       android.support.v4.app.NotificationCompat.Builder    mBuilder =
                new android.support.v4.app.NotificationCompat.Builder(this)
                .setContent(contentView)
    
       manager.notify(0, mBuilder.build());
    

提交回复
热议问题