-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Push Notification issue #740
Comments
I solved the problem only partially by bumping my Still the problem remains while Notification system tries to access icon when displaying push notifications from background activity rather than the main app itself. It would be nice to address it in the future version and to be able to change the For instance:
|
Possibly duplicate of #748 ? @KocWozniakPiotr can you share the full output? |
Not really. This is not about the background service itself but more about Notification Class not flexible enough. Ideally you would preferably want to send notifications from a background service and not app itself. This leads to the conflict between notification having same ID as background service. I did modify the notification class to have a different ID - avoiding the ID of the background service and now it works without any problem. Since the latest buildozer introduced custom icon_path for later usage as a |
Hello. I'm having trouble getting notifications from background service. I'm getting errors. Any chance you could provide a simple example including main.py , service.py and buildozer.spec ? I think I did everything right, but every time I get an error. |
Hi. Notifications works from the main app using: main.py import plyer
...
plyer.notification.notify(title = "Hello", message = "World!") From the service i've tested the following cases: service_01.py import plyer
...
plyer.notification.notify(title = "Hello", message = "World!") from plyer import notification
...
notification.notify(title = "NOTIFY from Service", message = "Hello!") in boot cases i get
Using: from plyer.platforms.android import notification
PlyerNotification = notification.instance()
...
PlyerNotification.notify(title = "NOTIFY from Service", message = "Hello!") I get error on
@KocWozniakPiotr please, can you share the modification you did to the notification class? i've found out that in PythonService.java the foreground service notification is created with it's own channel: ...
String NOTIFICATION_CHANNEL_ID = "org.kivy.p4a" + getServiceId();
String channelName = "Background Service" + getServiceId();
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName,
NotificationManager.IMPORTANCE_NONE);
chan.setLightColor(Color.BLUE);
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.createNotificationChannel(chan);
Notification.Builder builder = new Notification.Builder(context, NOTIFICATION_CHANNEL_ID);
builder.setContentTitle(contentTitle);
builder.setContentText(contentText);
builder.setContentIntent(pIntent);
builder.setSmallIcon(smallIconId);
notification = builder.build();
}
startForeground(getServiceId(), notification); while in package_name = activity.getPackageName()
self._ns = None
self._channel_id = package_name |
Sorry guys to resurrect old issue. Apologize for not being active during the last 6 months, to be able to reply! PythonService.java wasn't modified. First of all, If you want the notification properly working inside the background service process like in my case:
You can modify notification.py Notification class inside facades directory to add the
If using only one channel is all you want, just use only single channel for instance 0 or 1. Otherwise feel free to add as many channels as you please.
regarding channel service inside notification.py in the path /platforms/android You need to add the channel there and optionally add Drawable which is sadly not supported anymore AFAIK. There are also few other changes for instance: This is my notification.py :
In your builder.specs enable this line: you need also to make a dir called data/legal_icons in your project directory and place there your png icon for notifications. It will be then exported during deployment. THATS IT! It's a pretty hard work around but this is the only way I managed to get notifications to work on many android APIs. I don't remember exact details what I changed here but this is a working fix which I'm using until now.
The main Service notification needs to be disabled manually by the user to hide it from the screen. There is no other way around I guess. And here is my service.py if anyone is interested:
Hope this helps someone! |
It seems plyer notification module works finally out of the box on Android. However I'm having a hard time getting push notifications to work inside my
service.py
script which runs in foreground.When I start some notification from inside of main app
notify()
works fine. Also when a foregroundservice.py
runs alongside. But it fails when I implementnotify()
inside my foreground service. No matter if the app stays active, paused or I close it. The same happens.The main Service Notification stays sticky as it should and when notify() tries to generate a new push notification Service Notification dissapears for a second and appears back. However with no Title and content anymore. Just blank notification.
here is my logcat when background service tries to use plyer push_notification:
01-26 13:09:08.584 2275 2275 D SystemUILog: notification|NotificationListener:onNotificationPosted: StatusBarNotification(pkg=org.kivy.sampleapp user=UserHandle{0} id=1 tag=null key=0|org.kivy.sampleapp|1|null|10615: Notification(channel=org.kivy.p4a1 shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x62 color=0x00000000 vis=PRIVATE))
In my main.py I'm using the usual service.start()
from jnius import autoclass
service = autoclass('org.kivy.sampleapp.ServiceSyncing')
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
service.start(mActivity, '')
service.py
from jnius import autoclass
from plyer import notification
PythonService = autoclass('org.kivy.android.PythonService')
PythonService.mService.setAutoRestartService(True)
while True:
sleep(60)
notification.notify(title='Hey', message='testing')
buildozer.spec attached as a file
buildozer.txt
I'm kind of lost. I think it might have something to do with
id
orchannel_id
getting changed or because I'm not using the main package/activity ?I'm not very familiar with java code so I cant figure out how and where to alter the code.
Before
2.1.0
I was able to run it successfully.Any help or workaround for this would be great !
The text was updated successfully, but these errors were encountered: