nwenar abbas

nwenar abbas

  • 1.5k
  • 108
  • 2.9k

System.NullReferenceException: 'Object reference not set to an instanc

Feb 15 2022 11:23 AM

I have created a service to listen to all system and other apps is notification but I get an error when  the code that gets the  data from notification  excuted  

the line is string content = sbn.Notification.TickerText.ToString();

here is m services 

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Service.Notification;
using Android.Util;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android;

[Service(Label = "ServiceName", Permission = "android.permission.BIND_NOTIFICATION_LISTENER_SERVICE")]
[IntentFilter(new[] { "android.service.notification.NotificationListenerService" })]
public class NLService : NotificationListenerService
{
    public override void OnCreate()
    {
        base.OnCreate();
        Log.Info("start running", "Servico Criado");
    }
    public override void OnDestroy()
    {
        base.OnDestroy();
    }
    public override IBinder OnBind(Intent intent)
    {
        return base.OnBind(intent);
    }
    public override bool OnUnbind(Intent intent)
    {
        return base.OnUnbind(intent);
    }
    public override void OnNotificationPosted(StatusBarNotification sbn)
    {
       
        string packageName = sbn.PackageName;
// this line of code below has an error when the line excutes        

string content = sbn.Notification.TickerText.ToString();

 

 

        base.OnNotificationPosted(sbn);
    }

    public override void OnNotificationRemoved(StatusBarNotification sbn)
    {
        base.OnNotificationRemoved(sbn);
    }
}

 

 


Answers (3)