I am working on Android app and I have receive a broadcast for incoming calls and I need to create a notification in the notification tray.
I am trying the following
NotificationManager nm = (NotificationManager)this;
But this displays an error Cannot cast from PhoneStateManager to NotificationManager.
I’ve also tried using context instead of this but then says it can’t cast from PhoneStateManager to NotificationManager.
How can I create the notification from the PhoneStateListener, is this possible or do I need to pass it to a service?
Get an instance of it like the docs say:
Since you didn’t post more code, it’s hard to tell what you can use for
context. If you do have aContextvariable, use it. If your listener is contained in an Activity/Service doMyActivity.thisorMyService.thisinstead of thecontextvariable that I used in my code snippet.