kvdroid / Kvdroid

Some Pyjnius tools for Kivy-Android developments.
MIT License
94 stars 24 forks source link

notification import error #48

Closed lukmiik closed 9 months ago

lukmiik commented 10 months ago

Hello, when I run buildozer -v android deploy run logcat command this error occurs: ImportError: cannot import name 'create_notification' from 'kvdroid.tools.notification'.

kengoon commented 10 months ago

@lukmiik did you enable Androidx and added androidx Gradle dependency in your spec file?

There's an ongoing update #47 on the notification module with a clear instructions on how to effectively use it. So I suggest you wait.

lukmiik commented 10 months ago

When I uncomment this line in buildozer.spec: android.gradle_dependencies = androidx.work:work-runtime:2.2.0 app just crashes immediately

kengoon commented 10 months ago

@lukmiik I don't know about this androidx.work:work-runtime:2.2.0. We use the core library to test androidx.core:core:1.6.0 and make sure you have android.enable_androidx = True uncommented

lukmiik commented 10 months ago

Now it works, thanks. Although the line small_icon=get_resource("drawable").ico_nocenstore produces this error AttributeError: type object 'org.smart_shirt.smart_shirt.R$drawable' has no attribute 'ico_nocenstore'. I changed small_icon to 1 and it works fine. What can I do to make notification look like yours in the demo, ideally I would like expandable notification without buttons reply etc. Mine looks like this using code: ` create_notification(

small_icon=get_resource("drawable").ico_nocenstore, # app icon

            small_icon=1,
            channel_id="1", title="You have a message",
            text="hi, just wanted to check on you",
            ids=1, channel_name=f"ch1",
            large_icon="assets/profile-pic.png",
            expandable=True,
            set_large_icon=True,
            small_icon_color=Color().rgb(0x00, 0xC8, 0x53),  # 0x00 0xC8 0x53 is same as 00C853
            big_picture="assets/profile-pic.png"
        )`

my_notification and mine doesn't vibrate and you can't see them in notifications panel on the phone but on the demo version you can. I copied this code from demo but with it nothing shows up, there is just sound on my app. create_notification( small_icon=1, channel_id ='1', title='KvDroid', text='hello from kvdroid androidx notification', ids=1, channel_name='ch1', large_icon='assets/icon.png', big_picture='assets/icon.png', action_title1='CLICK', action_title2='PRESS', reply_title='REPLY', set_reply=True, expandable=True, set_large_icon=True, add_action_button1=True, add_action_button2=True, small_icon_color=Color().parseColor('#2962FF') )

Thanks for all your help

kengoon commented 9 months ago

@lukmiik the icon was just an example, that is what I named mine. I will update the doc to properly reflect the usage Also note that 1 is not your icon. You can get your actual icon by get_resource("mipmap").icon

lukmiik commented 9 months ago

Okay, thank you so much

Hypocrate-code commented 9 months ago

I jump on this issue because it seems more appropriate for my needs ; I also have this error : ImportError: cannot import name 'create_notification' from 'kvdroid.tools.notification because it fails importing the class "androidx.core.app.ActivityCompat" which is required by the file kvdroid/jclass/androidx/init.py, which is required by kvdroid/tools/notification.py

how can i fix this ? here is the whole log : log.txt and here is my buildozer.spec file : buildozer.txt

kengoon commented 9 months ago

When I told you to run this

buildozer android clean
buildozer android debug

I guess you didn't do that. Clean your entire buildozer, infact delete the . buildozer directory and start build again. Your error is not an issue with kvdroid, it is an exception that we coded there so that if you don't have the androidx.core package and androidx enabled, your notification would throw an exception error .

Your issue still has nothing to do with kvdroid

Hypocrate-code commented 9 months ago

I swear it's not working, I'm pretty sure i did it when you asked me to, and now i just did it again (deleted .buildozer and recompiled) and it still doesn't work. You recommended me to check for other version of androidx.core, I tried 1.8.0 one but it doesn't work, please what can i do it ?

kengoon commented 9 months ago

@Hypocrate-code I don't know why you keep having that issue. The original author of this issue confirmed that actions I told him to perform are working for him. At this stage I can't help you anymore. Maybe you should uninstall your app and reinstall from the bin directory

Hypocrate-code commented 9 months ago

Do you think using kvdroid on a different Thread can cause problem ? I think i have issues because of this

kengoon commented 9 months ago

@Hypocrate-code yes

Hypocrate-code commented 9 months ago

Now i have this error TypeError: create_notification() got an unexpected keyword argument 'priority', any idea ?

here is my code : create_notification( small_icon=get_resource("drawable").ic_launcher, channel_id="ch1", title="HypLoad", text=f"{'Download' if options_json['language'] == 'en'} {content}", ids=1, channel_name="message", priority = NotificationCompat().PRIORITY_MAX )

'content' being a declared value Am I missing arguments ?

Hypocrate-code commented 9 months ago

@kengoon if i don't add the 'priority' argument, the create_notification function is executed (not creating any exception) but doesn't do anything. Am i missing something ?

kengoon commented 9 months ago

@Hypocrate-code the new update has not been released on pypi. You would have to use the Master branch

https://github.com/kvdroid/Kvdroid/archive/refs/heads/master.zip