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

AttributeError: 'org.kivy.android.PythonService' object has no attribute 'getComponentName' #748

Open
PythonLaboratory opened this issue Feb 25, 2023 · 0 comments

Comments

@PythonLaboratory
Copy link

Description

I have a simple Kivy application that has a foreground service. When I try to send a notification via plyer in this service, I get an error AttributeError: 'org.kivy.android.PythonService' object has no attribute 'getComponentName'

Full traceback

02-25 20:57:46.152  7264  7281 I Service : Android kivy bootstrap done. __name__ is __main__
02-25 20:57:48.122  7264  7281 I Service : Traceback (most recent call last):
02-25 20:57:48.122  7264  7281 I Service :   File "/home/suser/Projects/TestService/.buildozer/android/platform/build-arm64-v8a/build/python-installs/testservice/arm64-v8a/plyer/utils.py", line 97, in _ensure_obj
02-25 20:57:48.122  7264  7281 I Service :   File "/home/suser/Projects/TestService/.buildozer/android/platform/build-arm64-v8a/build/python-installs/testservice/arm64-v8a/plyer/platforms/android/notification.py", line 201, in instance
02-25 20:57:48.122  7264  7281 I Service :   File "/home/suser/Projects/TestService/.buildozer/android/platform/build-arm64-v8a/build/python-installs/testservice/arm64-v8a/plyer/platforms/android/notification.py", line 48, in __init__
02-25 20:57:48.122  7264  7281 I Service : AttributeError: 'org.kivy.android.PythonService' object has no attribute 'getComponentName'
02-25 20:57:48.122  7264  7281 I Service : Traceback (most recent call last):
02-25 20:57:48.122  7264  7281 I Service :   File "/home/suser/Projects/TestService/.buildozer/android/app/services/service.py", line 8, in <module>
02-25 20:57:48.122  7264  7281 I Service :   File "/home/suser/Projects/TestService/.buildozer/android/platform/build-arm64-v8a/build/python-installs/testservice/arm64-v8a/plyer/facades/notification.py", line 84, in notify
02-25 20:57:48.123  7264  7281 I Service :   File "/home/suser/Projects/TestService/.buildozer/android/platform/build-arm64-v8a/build/python-installs/testservice/arm64-v8a/plyer/facades/notification.py", line 93, in _notify
02-25 20:57:48.123  7264  7281 I Service : NotImplementedError: No usable implementation found!

Code

main.py

from kivymd.app import MDApp

from kivymd.uix.screen import MDScreen
from kivymd.uix.button import MDRectangleFlatButton

from kivy import platform

class MainApp(MDApp):

    def build(self):
            
        try:

            self.start_service('Service')

        except:

            import sys

            print('SERVICE ERROR:', sys.exc_info())
            

        return MDScreen(
            MDRectangleFlatButton(
                text="Hello, World",
                pos_hint={"center_x": 0.5, "center_y": 0.5},
            )
        )

    def start_service(self, name):

        from android import mActivity
        from jnius import autoclass

        context = mActivity.getApplicationContext()
        service_name = str(context.getPackageName()) + '.Service' + name
        service = autoclass(service_name)
        service.start(mActivity, '')
        
        return service


MainApp().run()

service.py

import time

import plyer

if __name__ == '__main__':

    for i in range(100):
        
        plyer.notification.notify('Hello', 'Hello world!')
        
        print(i)
        time.sleep(5)

buildozer.spec

[app]

title = Test Service

package.name = testservice

package.domain = com.live.test

source.dir = .

source.include_exts = py,png,jpg,kv,spec,sql

version = 0.1

# version.regex = __version__ = ['"](.*)['"]
# version.filename = %(source.dir)s/main.py

requirements = python3,kivy==master,https://github.com/kivymd/kivymd/archive/master.zip,android,pyjnius,plyer

orientation = portrait

# (list) List of service to declare
services = Service:./services/service.py:foreground:sticky



#
# Android specific
#

fullscreen = 0

android.permissions = INTERNET,FOREGROUND_SERVICE,POST_NOFTICATIONS

#android.api = 27

#android.minapi = 21

#android.sdk = 20

#android.ndk = 19b

#android.ndk_api = 21

android.accept_sdk_license = True

#android.entrypoint = org.kivy.android.PythonActivity

#android.activity_class_name = org.kivy.android.PythonActivity

#android.extra_manifest_xml = ./src/android/extra_manifest.xml

#android.extra_manifest_application_arguments = ./src/android/extra_manifest_application_arguments.xml

#android.service_class_name = org.kivy.android.PythonService

android.archs = arm64-v8a



#
# Python for android (p4a) specific
#

p4a.branch = master


[buildozer]

# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
log_level = 2

Versions

python-for-android: master
plyer: 2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant