Skip to content
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

Notification is not working in android #93

Closed
afreport opened this issue Aug 26, 2014 · 20 comments
Closed

Notification is not working in android #93

afreport opened this issue Aug 26, 2014 · 20 comments

Comments

@afreport
Copy link

Linux (ubuntu 14.04)
Android 4.0.4 (Samsung GALAXY Note)

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2

$ pip freeze
Kivy==1.8.0
Kivy-Garden==0.1.1
plyer==1.1.2
pyjnius==1.3.0
buildozer==0.15
Cython==0.20.2
PyOpenGL==3.0.2
pyOpenSSL==0.13
pygame==1.9.1release

  1. Download plyer / examples / notification /
  2. $ buildozer android debug deploy run
  3. move PlyerNotificationExample-1.0-debug.apk to android phone and install PlyerNotificationExample-1.0-debug.apk
  4. Touch 'Simple Notification', Plyer Notification Example (application) is shutdown*
  5. Touch 'Fancy Notification', Plyer Notification Example (application) is shutdown*
@afreport afreport changed the title notification for android is not working notification is not working in android Aug 26, 2014
@afreport afreport changed the title notification is not working in android Notification is not working in android Aug 26, 2014
@trivedigaurav
Copy link
Member

Thanks @afreport for the report. Could you also attach the logs you get from logcat?
To do this, you will need to run $ adb logcat | grep python with your phone connected to your computer and launch the application.

@afreport
Copy link
Author

*** RUN 'Plyer Notification Example' ***

V/python ( 1776): metadata fullscreen is0
I/python ( 1776): Starting audio thread
I/python ( 1776): Initialize Python for Android
I/python ( 1776): ['/data/data/org.test.notiexample/files/lib/python2.7/site-packages', '/data/data/org.test.notiexample/files/lib/site-python']
I/python ( 1776): Android path ['/data/data/org.test.notiexample/files/lib/python27.zip', '/data/data/org.test.notiexample/files/lib/python2.7', '/data/data/org.test.notiexample/files/lib/python2.7/lib-dynload', '/data/data/org.test.notiexample/files/lib/python2.7/site-packages', '/data/data/org.test.notiexample/files', '/data/data/org.test.notiexample/files/_applibs']
I/python ( 1776): Android kivy bootstrap done. name is main
I/python ( 1776): Run user program, change dir and execute main.py
I/python ( 1776): [INFO ] Kivy v1.8.0
I/python ( 1776): [INFO ] [Logger ] Record log in /data/data/org.test.notiexample/files/.kivy/logs/kivy_14-08-31_3.txt
I/python ( 1776): [INFO ] [Factory ] 157 symbols loaded
I/python ( 1776): [DEBUG ] [Cache ] register <kv.lang> with limit=None, timeout=Nones
I/python ( 1776): [DEBUG ] [Cache ] register <kv.image> with limit=None, timeout=60s
I/python ( 1776): [DEBUG ] [Cache ] register <kv.atlas> with limit=None, timeout=Nones
I/python ( 1776): /data/data/org.test.notiexample/files/lib/python2.7/site-packages/kivy/core/image/img_pygame.py:12: RuntimeWarning: import cdrom: No module named cdrom
I/python ( 1776): (ImportError: No module named cdrom)
I/python ( 1776): [INFO ] [Image ] Providers: img_tex, img_dds, img_pygame, img_gif (img_pil ignored)
I/python ( 1776): [DEBUG ] [Cache ] register <kv.texture> with limit=1000, timeout=60s
I/python ( 1776): [DEBUG ] [Cache ] register <kv.shader> with limit=1000, timeout=3600s
I/python ( 1776): [DEBUG ] [App ] Loading kv <./notificationdemo.kv>
I/python ( 1776): [DEBUG ] [Window ] Ignored <egl_rpi> (import error)
I/python ( 1776): [INFO ] [Window ] Provider: pygame(['window_egl_rpi'] ignored)
I/python ( 1776): [DEBUG ] [WinPygame ] Set window to fullscreen mode
I/python ( 1776): [DEBUG ] [Window ] Display driver android
I/python ( 1776): [DEBUG ] [Window ] Actual window size: 800x1230
I/python ( 1776): [INFO ] [GL ] OpenGL version <OpenGL ES 2.0 2184622>
I/python ( 1776): [INFO ] [GL ] OpenGL vendor
I/python ( 1776): [INFO ] [GL ] OpenGL renderer <Adreno (TM) 220>
I/python ( 1776): [INFO ] [GL ] OpenGL parsed version: 2, 0
I/python ( 1776): [INFO ] [GL ] Texture max size <4096>
I/python ( 1776): [INFO ] [GL ] Texture max units <16>
I/python ( 1776): [DEBUG ] [Shader ] Fragment compiled successfully
I/python ( 1776): [DEBUG ] [Shader ] Vertex compiled successfully
I/python ( 1776): [INFO ] [Shader ] program: <--From Fragment Shader:
I/python ( 1776): --From Vertex Shader:
I/python ( 1776): Link was successful.>
I/python ( 1776): [DEBUG ] [ImagePygame ] Load </data/data/org.test.notiexample/files/lib/python2.7/site-packages/kivy/data/glsl/default.png>
I/python ( 1776): [INFO ] [Support ] Android install hooks
I/python ( 1776): [INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
I/python ( 1776): [INFO ] [Text ] Provider: pygame
I/python ( 1776): [DEBUG ] [Cache ] register <kv.loader> with limit=500, timeout=60s
I/python ( 1776): [INFO ] [Loader ] using a thread pool of 2 workers
I/python ( 1776): [DEBUG ] [Cache ] register <textinput.label> with limit=None, timeout=60.0s
I/python ( 1776): [DEBUG ] [Cache ] register <textinput.width> with limit=None, timeout=60.0s
I/python ( 1776): [DEBUG ] [Atlas ] Load </data/data/org.test.notiexample/files/lib/python2.7/site-packages/kivy/data/../data/images/defaulttheme.atlas>
I/python ( 1776): [DEBUG ] [Atlas ] Need to load 1 images
I/python ( 1776): [DEBUG ] [Atlas ] Load </data/data/org.test.notiexample/files/lib/python2.7/site-packages/kivy/data/../data/images/defaulttheme-0.png>
I/python ( 1776): [DEBUG ] [ImagePygame ] Load </data/data/org.test.notiexample/files/lib/python2.7/site-packages/kivy/data/../data/images/defaulttheme-0.png>
I/python ( 1776): [INFO ] [GL ] NPOT texture support is available
I/python ( 1776): [INFO ] [OSC ] using for socket
I/python ( 1776): [DEBUG ] [Base ] Create provider from android
I/python ( 1776): [INFO ] [Base ] Start application main loop
I/python ( 1776): [INFO ] [Android ] found 17 joystick
I/python ( 1776): [INFO ] [Android ] create joystick <0>
I/python ( 1776): [INFO ] [Android ] discard joystick <0> cause no button
I/python ( 1776): [INFO ] [Android ] create joystick <1>
I/python ( 1776): [INFO ] [Android ] create joystick <2>
I/python ( 1776): [INFO ] [Android ] create joystick <3>
I/python ( 1776): [INFO ] [Android ] create joystick <4>
I/python ( 1776): [INFO ] [Android ] create joystick <5>
I/python ( 1776): [INFO ] [Android ] create joystick <6>
I/python ( 1776): [INFO ] [Android ] create joystick <7>
I/python ( 1776): [INFO ] [Android ] create joystick <8>
I/python ( 1776): [INFO ] [Android ] create joystick <9>
I/python ( 1776): [INFO ] [Android ] create joystick <10>
I/python ( 1776): [INFO ] [Android ] create joystick <11>
I/python ( 1776): [INFO ] [Android ] create joystick <12>
I/python ( 1776): [INFO ] [Android ] create joystick <13>
I/python ( 1776): [INFO ] [Android ] create joystick <14>
I/python ( 1776): [INFO ] [Android ] create joystick <15>
I/python ( 1776): [INFO ] [Android ] create joystick <16>

*** NOTHING. I JUST PRESS ENTER IN TERMINAL ***
*** TOUCH 'Simple Notification' OR 'Fancy Notification' ***

I/python ( 1776): [INFO ] [Base ] Leaving application in progress...
I/python ( 1776): Traceback (most recent call last):
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/app/main.py", line 44, in
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/app.py", line 792, in run
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/base.py", line 481, in runTouchApp
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/core/window/window_pygame.py", line 381, in mainloop
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/core/window/window_pygame.py", line 287, in _mainloop
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/base.py", line 324, in idle
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/base.py", line 309, in dispatch_input
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/base.py", line 220, in post_dispatch_input
I/python ( 1776): File "_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4552)
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/core/window/init.py", line 648, in on_motion
I/python ( 1776): File "_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4552)
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/core/window/init.py", line 660, in on_touch_down
I/python ( 1776): File "_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4552)
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/uix/widget.py", line 284, in on_touch_down
I/python ( 1776): File "_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4552)
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/uix/behaviors.py", line 93, in on_touch_down
I/python ( 1776): File "_event.pyx", line 312, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4506)
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/kivy/lang.py", line 1299, in custom_callback
I/python ( 1776): File "./notificationdemo.kv", line 18, in
I/python ( 1776): on_press: root.do_notify(mode='normal')
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/app/main.py", line 35, in do_notify
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/plyer/facades.py", line 98, in notify
I/python ( 1776): File "/home/afreport/notification/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/site-packages/plyer/platforms/android/notification.py", line 27, in _notify
I/python ( 1776): AttributeError: 'android.app.Notification$Builder' object has no attribute 'build'
I/python ( 1776): Python for android ended.

@trivedigaurav
Copy link
Member

Thanks a lot @afreport. The problem is indeed with the android notification facade implementation. I haven't had a chance yet to look into the source - https://github.com/kivy/plyer/commits/master/plyer/platforms/android/notification.py.

@tito
Copy link
Member

tito commented Sep 29, 2014

Ping @brousch ?

@brousch
Copy link
Contributor

brousch commented Oct 10, 2014

What's your buildozer.spec look like? I'm specifically wondering about the android.api, android.minapi, android.sdk, and android.ndk settings.

I have had success using:
android.api = 14
android.minapi = 8
android.sdk = 23
android.ndk = 9d

@kashifpk
Copy link

kashifpk commented Nov 1, 2014

@brousch

I tried with

android.api = 14
android.minapi = 8
android.sdk = 23
android.ndk = 9c

and then with:

android.api = 14
android.minapi = 8
android.sdk = 23
android.ndk = 9d

Still the same error:

I/python  (14003):  AttributeError: 'android.app.Notification' object has no attribute 'build'
I/python  (14003): Python for android ended.

Using plyer APIs on Linux work but on android it fails. I tried notification and got the same result (working on Linux and crushing the app on android).

Any update on this issue?

@mbouden
Copy link

mbouden commented Nov 7, 2014

Same error with same log message under Kivy launcher

@kashifpk
Copy link

kashifpk commented Nov 7, 2014

Could it be that plyer in recent releases or a specific combination of android ndk, sdk and plyer don't work? Any insights on this from the kivy team?

@brousch
Copy link
Contributor

brousch commented Nov 7, 2014

When I looked at it briefly a few weeks ago it seemed to only be broken on
Android 4.0. 2.3 and 4.2 seemed OK
On Nov 7, 2014 7:12 AM, "Kashif Iftikhar" [email protected] wrote:

Could it be that plyer in recent releases or a specific combination of
android ndk, sdk and plyer don't work? Any insights on this from the kivy
team?


Reply to this email directly or view it on GitHub
#93 (comment).

@kashifpk
Copy link

kashifpk commented Nov 7, 2014

I've tested this on android 4.2.1 and 4.03 and it's broken on both. Any ideas on where the problem may be in Plyer? If it's python code then I can try to get it working and then submit a pull request.

@dkotik
Copy link

dkotik commented Nov 12, 2014

Android code in plyer just seems plain broken and redundant (.build is called twice?). I think it also grabs the wrong activity when you're trying to call it from PythonService. In addition, plyer works poorly with pyinstaller, has a major pain-in-the-butt dynamic loader that prevents it from manual inclusion. Altogether, just seems ill-written from the beginning. Today I pulled Android code out of plyer and run it manually within my PythonService like so:

from jnius import autoclass
PythonService = autoclass('org.renpy.android.PythonService')
activity = PythonService.mService
Context = autoclass('android.content.Context')
NotificationBuilder = autoclass('android.app.Notification$Builder')
AndroidString = autoclass('java.lang.String')
Drawable = autoclass(activity.getPackageName() + '.R$drawable')

def nt(title, msg):
notificationService = activity.getSystemService(Context.NOTIFICATION_SERVICE)
noti = NotificationBuilder(activity)
noti.setContentTitle(AndroidString(title))
noti.setContentText(AndroidString(msg))
noti.setSmallIcon(Drawable.icon)
noti.setAutoCancel(True)
notificationService.notify(0, noti.build())

@kashifpk
Copy link

@vigilantzealot Can you point out the issues with current plyer code? I can try updating it and then have a pull request ready for the kivy team if that's ok with the team?

@trivedigaurav
Copy link
Member

That would be great. Thanks!

On Wed, Nov 12, 2014 at 10:27 AM, Kashif Iftikhar [email protected]
wrote:

@vigilantzealot https://github.com/vigilantzealot Can you point out the
issues with current plyer code? I can try updating it and then have a pull
request ready for the kivy team if that's ok with the team?


Reply to this email directly or view it on GitHub
#93 (comment).

@dkotik
Copy link

dkotik commented Nov 12, 2014

@kashifpk sure. are you plyer project leader? i can send what i have on windows/android once i am done with the implementation. the biggest problem with plyer is its dynamic import statement. It needs to use plain inheritance and leave hooks for extension - really basic one-class inheritance. That would make the code portable, easy to use. private-send me your email, i can get back to you with in a week or two.

@kashifpk
Copy link

@vigilantzealot No I'm not yet involved with plyer or kivy for that matter. I myself was facing the same issues with plyer. Since it seems that kivy team members are busy focusing on other aspects of the framework (probably for the upcoming release) and this issue has been open for more than a couple of months; I thought I could contribute to it.

You can contact me at: kashif [at] compulife.com.pk

@dkotik
Copy link

dkotik commented Nov 12, 2014

cool, i'll contact you with what i have soon. i am basically rewriting plyer for myself due to annoyances like inability to add maximize window function when notification is clicked (no easy way to patch it in either). For windows, I am using SysTrayIcon.py by Simon as base - it also has capability to make a basic menu.

@brousch
Copy link
Contributor

brousch commented Nov 12, 2014

The Kivy team would love to see your ideas about Plyer improvements. The
kivy-dev Google group (https://groups.google.com/forum/#!forum/kivy-dev) is
probably the best place to discuss them.

On Wed, Nov 12, 2014 at 1:37 PM, vigilantzealot [email protected]
wrote:

cool, i'll contact you with what i have soon. i am basically rewriting
plyer for myself due to annoyances like inability to add maximize window
function when notification is clicked (no easy way to patch it in either).
For windows, I am using SysTrayIcon.py by Simon as base - it also has
capability to make a basic menu.


Reply to this email directly or view it on GitHub
#93 (comment).

Ben Rousch
[email protected]
http://clusterbleep.net/

@kashifpk
Copy link

Don't know if it helps but commenting out the following code

    if SDK_INT >= 16:
        noti = noti.build()
    else:
        noti = noti.getNotification()

at https://github.com/kivy/plyer/blob/master/plyer/platforms/android/notification.py#L27 made the notifications work again. I'm ignoring the SDK version here but not calling any of the methods ( build() or getNotification() ) and having it work suggests that this code can be ignored?

@dkotik
Copy link

dkotik commented Nov 13, 2014

You'll see a little bit below those lines noti.build() is called again (not needed). remove ".build()" there

kashifpk added a commit to kashifpk/plyer that referenced this issue Nov 13, 2014
@kashifpk
Copy link

@vigilantzealot thanks, followed your advice and it's fixed.

@tito tito closed this as completed in 95ca343 Nov 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants