kvdroid / Kvdroid

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

Feature for getting intent results, and applying actions performed on Notification, with docuementation #47

Closed kengoon closed 9 months ago

kengoon commented 10 months ago

Fixes #44 Fixes #48

kengoon commented 9 months ago

@yunus-ceyhan please review the code, Don't merge yet as I have not updated the doc on README.md. You can run a simple test with the code below. Request for notification permission if you are targeting API 33 and above. also add the permission to your .spec file

from kvdroid.jclass.android.graphics import Color
from kvdroid.tools.notification import create_notification
from kvdroid.tools import get_resource
fom android import activity as act

# Performs an action when a notification is tapped
act.bind(on_new_intent=print)

print(dir(get_resource("mipmap")))

from android.permissions import Permission, request_permissions  # NOQA
request_permissions(
    ["android.permission.POST_NOTIFICATIONS"
])

create_notification(
    small_icon=get_resource("mipmap").icon,  #replace .icon without the extension (.png, jpeg....) with whatever name you gave your application icon
    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/logo.png",
    small_icon_color=Color().rgb(0x00, 0xC8, 0x53),  # 0x00 0xC8 0x53 is same as 00C853
    big_picture="assets/logo.png",
    extras={"tap": ()}

)
yunus-ceyhan commented 9 months ago

@kengoon Unfortunately I can't, at least for a while. My laptop malfunctioned, I'm using my daughter's laptop temporarily which only has Windows and she doesn't want me to install much programming stuff :)

kengoon commented 9 months ago

@yunus-ceyhan I will solve that issue for you by sending you my PyjniusTester APK, you can directly test it on your phone, I will bundle the code into it so that you don't need to type at all. But you will need adb to see that when you tap the notification an action is performed

yunus-ceyhan commented 9 months ago

@yunus-ceyhan I will solve that issue for you by sending you my PyjniusTester APK, you can directly test it on your phone, I will bundle the code into it so that you don't need to type at all. But you will need adb to see that when you tap the notification an action is performed

fine then, I have adb

yunus-ceyhan commented 9 months ago

@kengoon btw why don't you use Firebase test lab if you need to test it on more devices with different APIs?

https://firebase.google.com/docs/test-lab

just install your pyjniustester then test on any device you want. for further devices, you can create a Huawei developer account and test it on Huawei devices as well.

kengoon commented 9 months ago

@yunus-ceyhan thanks for that, I have never heard of that before. I will check out firebase test lab right away. Is Huawei free?

Do I still need to send you the APK or should I go ahead and do the testing my self and then report back results so you can go ahead and merge?

yunus-ceyhan commented 9 months ago

@kengoon Yeah Huawei is free as well. Yes, it's fine if you test it on a few devices with different APIs, If there is no problem then inform me for the merge whenever it's ready.

yunus-ceyhan commented 9 months ago

@kengoon btw i have an idea but don't know if it's ridiculous.

We have a big performance issue when we intend to do some tasks with pyjnius. For instance, I needed to get all the installed apps activities for one of my apps. When I do that task with pyjnius it nearly takes 10 seconds to complete, but when I execute the same task with pure java it only takes 1 or 2 seconds. So I had to do that task for my app by calling that java function in PythonActivity.java at startup.

So my question is what if we find another way to communicate with Java to do those tasks kvdroid provides? How to create that channel?

I tried it with OSC protocol just like how we do it to communicate with service.py and actually, it worked but I'm not sure if it's a good approach.

It could be a separate project as well.

what do you think?

kengoon commented 9 months ago

@yunus-ceyhan that's exactly what I had in mind too, I wanted to bring the issue up to you but I was a bit not so sure you may like the idea. I think we should start a separate project. In that separate project we will perform all those functions in kvdroid with pure java and then build it into a library that can be added in the Gradle dependency.

I don't know how efficient OSC would be, can you like lay out an example code of how you call Java code from OSC.... Let's way our options before we start

yunus-ceyhan commented 9 months ago

@kengoon actually we cant call functions directly, osc only provides sending messages, we could use python-osc library to send messages as commands then create a java listener with using java oscp5 library, java would get that message (command) analyze then do the task you requested and then send back the result to python client as a message again. the example was in my malfunctioned laptop, but you can ask chat gpt to create a python script to send message via osc and a java listener to get and send back the result.

kengoon commented 9 months ago

@yunus-ceyhan I think it's doable with osc, I did some little research on it just few minutes ago (I will still conduct a further extensive research to know the implications).

The idea I currently have on using it, is to wrap it around async await and then create and build an API (I mean API code not url) around the entire codebase.

I would create a sample code to test this concept by tomorrow or next. For now I would head into more extensive research.

yunus-ceyhan commented 9 months ago

Ok. let me know when you have a working draft of it.

kengoon commented 9 months ago

@yunus-ceyhan all good, go ahead and merge