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

Error: "PushNotifications" plugin is not implemented on android #2312

Open
mafineeek opened this issue Feb 9, 2025 · 1 comment
Open

Error: "PushNotifications" plugin is not implemented on android #2312

mafineeek opened this issue Feb 9, 2025 · 1 comment
Labels

Comments

@mafineeek
Copy link

mafineeek commented Feb 9, 2025

Bug Report

Plugin(s)

"@capacitor/push-notifications": "^7.0.0"

Capacitor Version


PS E:\Friendify\web> npx cap doctor
   Capacitor Doctor   

Latest Dependencies:

  @capacitor/cli: 7.0.1
  @capacitor/core: 7.0.1
  @capacitor/android: 7.0.1
  @capacitor/ios: 7.0.1

Installed Dependencies:

  @capacitor/android: 7.0.1
  @capacitor/ios: 7.0.1
  @capacitor/cli: 7.0.1
  @capacitor/core: 7.0.1

[error] Main activity file (MainActivity) is missing
(MainActivity.java is not missing, can't figure out why there is such error)

Platform(s)

Current Behavior

Expected Behavior

Code Reproduction

import { PushNotifications } from '@capacitor/push-notifications';
import { Capacitor } from '@capacitor/core';
import { Dialog } from '@capacitor/dialog';
import axiosInstance from './utils/axiosInstance';

export const registerPushNotifications = async () => {
    // Sprawdź czy urządzenie to Android/iOS (natywna aplikacja)
    if (!Capacitor.isNativePlatform()) {
        console.log('📱 Powiadomienia push są dostępne tylko w natywnej aplikacji');
        return;
    }

    try {
        // Sprawdź uprawnienia
        let permStatus = await PushNotifications.checkPermissions();

        if (permStatus.receive === 'prompt') {
            permStatus = await PushNotifications.requestPermissions();
        }

        if (permStatus.receive !== 'granted') {
            throw new Error('Brak uprawnień do powiadomień');
        }

        // Zarejestruj się do powiadomień
        await PushNotifications.register();

        // Dodaj listenery
        await addListeners();

        return true;
    } catch (error) {
        console.error('❌ Błąd podczas rejestracji powiadomień:', error);
        throw error;
    }
};

const addListeners = async () => {
    await PushNotifications.addListener('registration', (token) => {
        console.log('📱 Token push:', token.value);
        // Tutaj możesz wysłać token do swojego API
    });

    await PushNotifications.addListener('registrationError', (error) => {
        console.error('❌ Błąd rejestracji push:', error);
    });

    await PushNotifications.addListener('pushNotificationReceived', (notification) => {
        console.log('📱 Otrzymano powiadomienie:', notification);
    });

    await PushNotifications.addListener('pushNotificationActionPerformed', (notification) => {
        console.log('📱 Kliknięto powiadomienie:', notification);
    });
};


//PushNotificationPrompt.tsx
import { Dialog } from '@capacitor/dialog';
import { useState } from 'react';
import { registerPushNotifications } from '../pushNotifications';
import SlideUpCard from './SlideUpCard';
import { Capacitor } from '@capacitor/core';
import { useTranslation } from 'react-i18next';

export const PushNotificationPrompt = () => {
    const [showPrompt, setShowPrompt] = useState(Capacitor.isNativePlatform());
    const { t } = useTranslation();

    const handleEnableNotifications = async () => {
        try {
            await registerPushNotifications();
            setShowPrompt(false);
        } catch (error) {
            console.error('❌ Błąd podczas rejestracji powiadomień:', error);
            await Dialog.alert({
                title: t('notifications.error.title'),
                message: t('notifications.error.message'),
            });
        }
    };

    if (!Capacitor.isNativePlatform()) return null; // Passes - I can see the SlideUpCard

    return (
        <SlideUpCard 
            isVisible={showPrompt} 
            onClose={() => setShowPrompt(false)}
            closeOnBackdropClick={false}
        >
            <div className="text-white">
                <h3 className="text-xl font-bold mb-2">{t('notifications.enable.title')}</h3>
                <p className="text-gray-300 mb-4">
                    {t('notifications.enable.description')}
                </p>
                <div className="flex gap-3">
                    <button
                        onClick={() => setShowPrompt(false)}
                        className="flex-1 py-3 px-4 rounded-lg border border-gray-600 text-white hover:bg-gray-800 transition-colors"
                    >
                        {t('notifications.later')}
                    </button>
                    <button
                        onClick={handleEnableNotifications}
                        className="flex-1 py-3 px-4 rounded-lg bg-white text-black hover:bg-gray-200 transition-colors"
                    >
                        {t('notifications.enable.now')}
                    </button>
                </div>
            </div>
        </SlideUpCard>
    );
}; 

Other Technical Details

Additional Context

Capacitor/Console ok.mafineeek.hango E File: https://localhost/assets/index-CyE89Nx6.js - Line 238 - Msg: Uncaught (in promise) Error: "PushNotifications" plugin is not implemented on android

@ionitron-bot ionitron-bot bot added the triage label Feb 9, 2025
@mafineeek
Copy link
Author

I'm pretty sure that it worked with Capacitor 6

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

No branches or pull requests

1 participant