Call a notification listener inside a background service in android studio

前端 未结 2 812
栀梦
栀梦 2021-01-07 02:19

I have a background service running and a notification listener. I want to call the notification listener from the background service and it does not seem to work. I have be

2条回答
  •  悲哀的现实
    2021-01-07 02:50

    Did you defined your services in your manifest. For notification service you need to write permission also.

            
    
            
                
                    
                
            
    

    if you want to show notification in that case you need to write this code also:

     NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this);
                ncomp.setContentTitle("My Notification");
                ncomp.setContentText("Notification Listener Service Example");
                ncomp.setTicker("Notification Listener Service Example");
                ncomp.setSmallIcon(R.mipmap.ic_launcher);
                ncomp.setAutoCancel(true);
                nManager.notify((int)System.currentTimeMillis(),ncomp.build());
    

    or did you provide the notification access to your app? Go to your settings and check notification access to your app provided or not?

提交回复
热议问题