Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Question about localNotification on Android #2162

Closed
guaaak opened this issue Sep 25, 2021 · 15 comments
Closed

Question about localNotification on Android #2162

guaaak opened this issue Sep 25, 2021 · 15 comments
Labels

Comments

@guaaak
Copy link

guaaak commented Sep 25, 2021

Hi team,

I set up everything correctly on android, but the local push notification is not working. Is there any clue of this issue?
I created channel at beginning of app.
Also tried to use firebase to send notification and it worked.

Thanks!

@Dallas62
Copy link
Collaborator

Hi,
If it's not working is probably because you missed a mandatory parameter or not calling the method.
Regards

@guaaak
Copy link
Author

guaaak commented Sep 25, 2021

Hi,

const handleNotification = () => {
        PushNotification.localNotification({
            channelId: 'channel-id',
            title: 'test',
            message: 'My Notification Message',
        });
    };

Here is the function for push local notification, and I used a Pressable to trigger this function.
Everything works fine on ios simulator but there are no responses on android after pressing the button.

@guaaak
Copy link
Author

guaaak commented Sep 30, 2021

I'm current using "react-native-push-notification": "^8.1.0", but I tried like 8.0.1 and 7.x.x something. They are also not working for me...

@Dallas62
Copy link
Collaborator

Did you at least create the channel?

@guaaak
Copy link
Author

guaaak commented Sep 30, 2021

Yes, I created a channal

@Dallas62
Copy link
Collaborator

Can you share all the code used to trigger the notification ?
The example project is working fine, it's probably something you missed.

@guaaak
Copy link
Author

guaaak commented Oct 1, 2021

Code for creating channel:

const createNotificationChannel = () => {
        PushNotification.createChannel(
            {
                channelId: 'channel-id', // (required)
                channelName: 'My channel', // (required)
                channelDescription:
                    'A channel to categorise your notifications', // (optional) default: undefined.
                playSound: false, // (optional) default: true
                soundName: 'default', // (optional) See `soundName` parameter of `localNotification` function
                importance: Importance.HIGH, // (optional) default: Importance.HIGH. Int value of the Android notification importance
                vibrate: true, // (optional) default: true. Creates the default vibration pattern if true.
            },
            created => console.log(`createChannel returned '${created}'`), // (optional) callback returns whether the channel was created, false means it already existed.
        );
    };

code in index.js

PushNotification.configure({
    onNotification: function (notification) {
        console.log('NOTIFICATION:', notification);
    },
    requestPermissions: true,
});

and the above is code for triggering notification, and the function is called on a onPress

@binobose
Copy link

binobose commented Oct 1, 2021

The same is happening for me as well, I just tried with all the settings as given and followed everything step by step, still nothing happening on Android. Local notifications not showing up at all. No console logs as well. Please advise.

@Dallas62
Copy link
Collaborator

Dallas62 commented Oct 1, 2021

Did you change the value of:

        <!-- Change the value to true to enable pop-up for in foreground on receiving remote notifications (for prevent duplicating while showing local notifications set this to false) -->
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
                    android:value="false"/>

To true ?

Again I set up everything correctly on android doesn't mean everything is set as you want.
A reproducible exemple might help!
Regards.

@Dallas62 Dallas62 closed this as completed Oct 1, 2021
@Dallas62 Dallas62 reopened this Oct 1, 2021
@binobose
Copy link

binobose commented Oct 2, 2021

Yes made it to true already.

This is my manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.###">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
                  android:value="true"/>
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                  android:resource="@color/white"/>
      <meta-data
          android:name="com.dieam.reactnativepushnotification.default_notification_channel_id"
          android:value="@string/default_notification_channel_id" />
      <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
      <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
      <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
          <intent-filter>
              <action android:name="android.intent.action.BOOT_COMPLETED" />
              <action android:name="android.intent.action.QUICKBOOT_POWERON" />
              <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
          </intent-filter>
      </receiver>
        <!-- <service
            android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service> -->
    </application>
</manifest>

I have copied the NotifService.js and the NotificationHandler.js from the example repo and called the methods exactly as given in the document. As I am working on a functional component, only the object definition in constructor had to be changed as below. Would that make any difference?

const [state, setState] = useState([])

const onRegister = token => {
  setState({registerToken: token.token, fcmRegistered: true})
}

const onNotif = notif => {
  Alert.alert(notif.title, notif.message)
}

const notif = useMemo(() => {
  return new NotifService(onRegister, onNotif)
}, [])

and then I invoked the local notification method on a TouchableOpacity as

onPress={() => { notif.localNotif()}}

What else needs to be done from my end? I am using the latest versions.

  • Also, I have seen a Token TextInput in the example code, where do we get the token from? What is that for?

@Dallas62
Copy link
Collaborator

Dallas62 commented Oct 2, 2021

I don't understand why everybody want to put no-component features inside a component. You can use a global variable to store the service, this will avoid lifecycle issue and double calls and allow background process in some cases.

To investigate, you can add some extra console.log in localNotif, to see if the method is called. If yes, you can look in the Android Log with adb logcat, there is probably a message in case of issue.

@binobose
Copy link

binobose commented Oct 2, 2021

Tried console in localNotif and its showing, but in logcat its showing this error

2021-10-02 16:06:58.806 348-8203/? E/FMQ: grantorIdx must be less than 3
2021-10-02 16:08:39.125 409-409/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2021-10-02 16:08:39.125 409-409/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe

@smontlouis
Copy link

@binobose did you find a solution ? Having the same issue

@binobose
Copy link

@binobose did you find a solution ? Having the same issue

@bulby97 Infact when I tried it in a real device it worked. I made an apk and installed it in my mobile, it worked without any issue. Just give it a try.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

4 participants