kivy / plyer

Plyer is a platform-independent Python wrapper for platform-dependent APIs
https://plyer.readthedocs.io
MIT License
1.56k stars 424 forks source link

Foreground Service Notification Error #793

Closed th3t1m closed 6 months ago

th3t1m commented 6 months ago

I have some trouble with foreground service push notifications I've tried use many ways (PyJnius, KVDroid, Plyer) it is not working all of this working on main app(and Plyer and PyJnius only on old version not on api >=31)

This is my case( is the same on Plyer2.2.1 and 2.2.0.dev0)

try:
    import plyer
    plyer.notification.notify(title=mess['_from'], message=mess['text'])
except Exception as e:
    print(f"PUSH SERVICE: FAIL 2: {str(e)}")

try:
    from plyer.platforms.android.notification import AndroidNotification
    notificator = AndroidNotification()
    notificator.notify(title=mess['_from'], message=mess['text'])
except Exception as e:
    print(f"PUSH SERVICE FAIL 3: {str(e)}")
12-20 20:51:18.391  4794  4881 I Push    : PUSH SERVICE: FAIL 2: No usable implementation found!
12-20 20:51:18.391  4794  4881 I Push    : PUSH SERVICE FAIL 3: 'org.kivy.android.PythonService' object has no attribute 'getComponentName'

on buildozer.spec I added all of this

services = Push:./services/push.py:foreground:sticky

and I have java class for this

package com.developer.xmppclient;

import android.content.Intent;
import android.content.Context;
import org.kivy.android.PythonService;

public class ServicePush extends PythonService {

    @Override
    public int startType() {
        return START_STICKY;
    }

    @Override
    protected int getServiceId() {
        return 2;
    }

    static private void _start(Context ctx, String smallIconName,
                             String contentTitle, String contentText, 
                             String pythonServiceArgument) {
        Intent intent = getDefaultIntent(ctx, smallIconName, contentTitle,
                     contentText, pythonServiceArgument);
        ctx.startService(intent);
    }

    static public void start(Context ctx, String pythonServiceArgument) {
        _start(ctx, "", "XMPP-Client", "Push", pythonServiceArgument);
    }

    static public void start(Context ctx, String smallIconName,
                             String contentTitle, String contentText, 
                             String pythonServiceArgument) {
    _start(ctx, smallIconName, contentTitle, contentText, pythonServiceArgument);
    }    

    static public Intent getDefaultIntent(Context ctx, String smallIconName,
                                          String contentTitle, String contentText, 
                                          String pythonServiceArgument) {
        Intent intent = new Intent(ctx, ServicePush.class);
        String argument = ctx.getFilesDir().getAbsolutePath() + "/app";
        intent.putExtra("androidPrivate", ctx.getFilesDir().getAbsolutePath());
        intent.putExtra("androidArgument", argument);
        intent.putExtra("serviceTitle", "XMPP-Client");
        intent.putExtra("serviceEntrypoint", "./services/push.py");
        intent.putExtra("pythonName", "Push");
        intent.putExtra("serviceStartAsForeground", "true");
        intent.putExtra("pythonHome", argument);
        intent.putExtra("pythonPath", argument + ":" + argument + "/lib");
        intent.putExtra("pythonServiceArgument", pythonServiceArgument);
        intent.putExtra("smallIconName", smallIconName);
        intent.putExtra("contentTitle", contentTitle);
        intent.putExtra("contentText", contentText);
        return intent;
    }

    @Override
    protected Intent getThisDefaultIntent(Context ctx, String pythonServiceArgument) {
        return ServicePush.getDefaultIntent(ctx, "", "", "", 
                                 pythonServiceArgument);
    }

    static public void stop(Context ctx) {
        Intent intent = new Intent(ctx, ServicePush.class);
        ctx.stopService(intent);
    }
}

can I call push notification from foreground service using Plyer?

ok-coder1 commented 6 months ago

Hi, this is a support issue, please use one of the support channels. Please close.

th3t1m commented 6 months ago

Hi, this is a support issue, please use one of the support channels. Please close.

do I need set some tags/labels on create or where I need to go to re-create this issue for support @ok-coder1

ok-coder1 commented 6 months ago

@th3t1m

Hi, this is a support issue, please use one of the support channels. Please close.

do I need set some tags/labels on create or where I need to go to re-create this issue for support @ok-coder1

CONTACT.md

ok-coder1 commented 6 months ago

Please close as not planned.