Git Product home page Git Product logo

Comments (24)

oney avatar oney commented on July 19, 2024

The configuration of notification is in here.
https://github.com/oney/react-native-gcm-android/blob/master/android/src/main/java/com/oney/gcm/RNGcmListenerService.java#L90
Modify to .setAutoCancel(true) will do the trick.
I recommend you create new GcmListenerService to handle notification in Java code by yourself.
Like this commit oney/TestGcm@5fa3614

from react-native-gcm-android.

Kuzmin avatar Kuzmin commented on July 19, 2024

@oney Rather than requiring users to write their own Java wrappers, which I think some people might be uncomfortable with (since they're on React Native), would it be possible to add methods for removing notifications from status bar and such behaviour inside the JS API?

That might lower barriers to entry and make this library usable for a wider audience.

from react-native-gcm-android.

oney avatar oney commented on July 19, 2024

Of course it is possible. Because the bridge of JS and native will be paused by default when the app enters background(onPause), we can't handle notifications in JS code.
Possible solution is
In JS

GcmAndroid.Setting.setAutoCancel(true);

In java, store the setting using SharedPreferences

SharedPreferences preferences = context.getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("GcmAndroid.Setting.autoCancel", autoCancel);
editor.commit();

And get the setting when getting notification.

SharedPreferences preferences = context.getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setAutoCancel(preferences.getBoolean("GcmAndroid.Setting.autoCancel", false))

May do it in the future and also welcome a PR!

from react-native-gcm-android.

 avatar commented on July 19, 2024

Hello,

First of all, awesome plugin, thanks a lot for making it.

I got the notifications working, I can now send notifications and they pop up.

However, I think I'm having the same problem as above:

  • Clicking them does not make them go away.
  • Clicking them does not open the app.

And I have another issue, which I'm not sure is related:

  • My eventListener for a notification when the app is on the foreground, does not seem to work.

I'm having some trouble getting this to work. I have no Java experience so it's kinda hard. I tried implementing your commit: oney/TestGcm@5fa3614 and also created a listener and added the change in my AndroidManifest.xml. But it does not work for me.

To see if it changes anything at all, I tried setting ContentTitle/ContentText to something else like:

.setContentTitle("test")
.setContentText("some message")

Am I overlooking something? What am I doing wrong?

from react-native-gcm-android.

oney avatar oney commented on July 19, 2024

@TxiX Which this module version you use?

from react-native-gcm-android.

 avatar commented on July 19, 2024

@oney Thanks for your reply. I use the following node modules:

"react-native": "0.17.0",
"react-native-gcm-android": "^0.1.0",
"react-native-system-notification": "0.0.7"

from react-native-gcm-android.

oney avatar oney commented on July 19, 2024

@TxiX
You're right. Three issues exist.
Please update to 0.1.1 from npm. These issue should be fixed.
Make sure to re-read README and modify codes.

from react-native-gcm-android.

 avatar commented on July 19, 2024

@oney First of: Thanks alot for the update!

However, I'm unable to get it to work.

I've copied the exact code from the README.md and put it in my index.android.js

I then changed all the things you mentioned in the README (looked at the commit).

The thing that works is registering, receiving a token and sending notifications. However I'm still unable to click them (I'm using the default RNGcmListenerService now, but I tried changing it and it had no effect).

I also see no console message from the 'notification' eventListener when I'm receiving the notification inside the app.

from react-native-gcm-android.

oney avatar oney commented on July 19, 2024

It's ok.
Can you try the demo again? https://github.com/oney/TestGcm
You can use the curl command in README to test sending gcm notification.

from react-native-gcm-android.

oney avatar oney commented on July 19, 2024

Run adb logcat and get logs when you click the notification, and paste the logs to me. Thanks!

from react-native-gcm-android.

 avatar commented on July 19, 2024

Hey.

So I tried to run the TestGCM package.

The TestGCM package does not show me the notification though.

This is what I get when running adb logcat:

12-22 19:19:45.451 30699 30736 I GCM     : GCM message com.testgcm 0:1450808385799742%f719a9d2f9fd7ecd
12-22 19:19:45.495  9261  9319 D RNGcmListenerService: sendNotification
12-22 19:19:45.496  9261  9261 D com.oney.gcm.GcmModule: GCMReceiveNotification BroadcastReceiver
12-22 19:19:45.496  9261  9261 W unknown:React: Calling JS function after bridge has been destroyed.

I'll see what adb logcat says on my own app.

from react-native-gcm-android.

oney avatar oney commented on July 19, 2024

Yeah, the source of the issue is unknown:React: Calling JS function after bridge has been destroyed..
Let me think about it.

from react-native-gcm-android.

 avatar commented on July 19, 2024

Alright.

Both the TestGcm and my own app crash when they're closed and not running in the background.

My own app gives the same kinda log when it's open. When it's closed, this is the log:

12-22 19:30:14.503 11881 11897 D RNGcmListenerService: sendNotification
12-22 19:30:14.510 29959 29983 W BroadcastQueue: Unable to launch app com.testgcm/10118 for broadcast Intent { act=com.oney.gcm.GCMReceiveNotification flg=0x10 (has extras) }: process is bad
12-22 19:30:14.513 11881 11881 D com.oney.gcm.GcmModule: sadfjasidfjliasf444
12-22 19:30:14.528 11881 11881 D BackgroundService: onStartCommand
12-22 19:30:14.564 11881 11881 I art     : Thread[1,tid=11881,Native,Thread*=0xb4df6500,peer=0x73fd12a0,"main"] recursive attempt to load library "/data/app/com.myapp-2/lib/arm/libreactnativejni.so"
12-22 19:30:14.643 11881 11910 W unknown:React: You seem to be running on device. Run 'adb reverse tcp:8081 tcp:8081' to forward the debug server's port to the device.
12-22 19:30:14.704 11881 11914 E         : Unable to load script from assets: index.android.bundle
12-22 19:30:14.705 11881 11914 E ReactNative: Got JS Exception: ReferenceError: Can't find variable: __fbBatchedBridge
12-22 19:30:14.706 11881 11914 E AndroidRuntime: FATAL EXCEPTION: mqt_js

Thanks again for your time.

from react-native-gcm-android.

oney avatar oney commented on July 19, 2024

Oh, crash when they're closed and not running in the background is due to lack of index.android.bundle.
Run below command to generate index.android.bundle, and then run react-native run-android

react-native bundle --platform android --dev false --entry-file index.android.js \
  --bundle-output android/app/src/main/assets/index.android.bundle \
  --assets-dest android/app/src/main/res/

from react-native-gcm-android.

 avatar commented on July 19, 2024

Alright! Got the following working now:

  • Can receive a notification when the app is closed.
  • Can click a notification and the app starts.

It still shows a dialog my app is crashed though. Even though the app opens after clicking on the notification.

12-23 06:03:57.132 30699 27756 I GCM     : GCM message com.myapp 0:1450847037856776%843f15aef9fd7ecd
12-23 06:03:57.203 29959 29983 I ActivityManager: Start proc 2415:com.myapp/u0a120 for broadcast com.myapp/com.google.android.gms.gcm.GcmReceiver
12-23 06:03:57.208  2415  2415 I art     : Late-enabling -Xcheck:jni
12-23 06:03:57.279  2415  2440 I GMPM    : App measurement is starting up
12-23 06:03:57.292  2415  2442 D RNGcmListenerService: sendNotification
12-23 06:03:57.293 29959 29983 W BroadcastQueue: Unable to launch app com.testgcm/10118 for broadcast Intent { act=com.oney.gcm.GCMReceiveNotification flg=0x10 (has extras) }: process is bad
12-23 06:03:57.295  2415  2415 D com.oney.gcm.GcmModule: sadfjasidfjliasf444
12-23 06:03:57.299  2415  2415 D BackgroundService: onStartCommand
12-23 06:03:57.340  2415  2415 I art     : Thread[1,tid=2415,Native,Thread*=0xb4df6500,peer=0x73fd12a0,"main"] recursive attempt to load library "/data/app/com.myapp-1/lib/arm/libreactnativejni.so"
12-23 06:03:57.400  2415  2445 W unknown:React: You seem to be running on device. Run 'adb reverse tcp:8081 tcp:8081' to forward the debug server's port to the device.
12-23 06:03:57.685  2415  2449 D com.oney.gcm.GcmModule: packageName: com.myapp
12-23 06:03:57.724  2415  2415 D AndroidRuntime: Shutting down VM
12-23 06:03:57.725 30242 30242 D PhoneStatusBar: disable: < expand ICONS* alerts SYSTEM_INFO* back home recent clock search quick_settings >
12-23 06:03:57.725  2415  2415 E AndroidRuntime: FATAL EXCEPTION: main
12-23 06:03:57.725  2415  2415 E AndroidRuntime: Process: com.myapp, PID: 2415
12-23 06:03:57.725  2415  2415 E AndroidRuntime: java.lang.AssertionError: Attached DialogModule to host with pending alert but no FragmentManager (not attached to an Activity).
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at com.facebook.infer.annotation.Assertions.assertNotNull(Assertions.java:28)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at com.facebook.react.modules.dialog.DialogModule.onHostResume(DialogModule.java:199)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at com.facebook.react.bridge.ReactContext.onResume(ReactContext.java:140)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at com.facebook.react.ReactInstanceManagerImpl.moveReactContextToCurrentLifecycleState(ReactInstanceManagerImpl.java:702)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at com.facebook.react.ReactInstanceManagerImpl.setupReactContext(ReactInstanceManagerImpl.java:545)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at com.facebook.react.ReactInstanceManagerImpl.access$700(ReactInstanceManagerImpl.java:78)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.onPostExecute(ReactInstanceManagerImpl.java:175)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.onPostExecute(ReactInstanceManagerImpl.java:155)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at android.os.AsyncTask.finish(AsyncTask.java:651)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at android.os.AsyncTask.-wrap1(AsyncTask.java)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:148)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:5417)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
12-23 06:03:57.725  2415  2415 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

When the app is open, I see the following (only after I opened it and do nothing):

12-23 06:07:55.613 30699 27756 I GCM     : GCM message com.myapp 0:1450847276352989%843f15aef9fd7ecd
12-23 06:07:55.645  2919  2991 D RNGcmListenerService: sendNotification
12-23 06:07:55.646  2919  2919 D com.oney.gcm.GcmModule: GCMReceiveNotification BroadcastReceiver
12-23 06:07:55.650  2919  2967 I ReactNativeJS: 'receive gcm notification', { data: 
12-23 06:07:55.650  2919  2967 I ReactNativeJS:    { info: '{"subject":"Hello GCM2","message":"Hello from the server side!"}',
12-23 06:07:55.650  2919  2967 I ReactNativeJS:      collapse_key: 'do_not_collapse' } }
12-23 06:07:55.651  2919  2967 I ReactNativeJS: 'GcmAndroid.isForground', true

And after a reload of the JS:

12-23 06:09:03.818 30699 27756 I GCM     : GCM message com.myapp 0:1450847344527411%843f15aef9fd7ecd
12-23 06:09:03.884  2919  3041 D RNGcmListenerService: sendNotification
12-23 06:09:03.891  2919  2919 D com.oney.gcm.GcmModule: GCMReceiveNotification BroadcastReceiver
12-23 06:09:03.891  2919  2919 W unknown:React: Calling JS function after bridge has been destroyed.

Hope this helps!

from react-native-gcm-android.

oney avatar oney commented on July 19, 2024

Very useful. Thanks for helping solve the problem.
The issue of reload of the JS is known to me. I will keep trying solving it.

About crash of Attached DialogModule to host with pending alert but no FragmentManager (not attached to an Activity), I think it happened in your app that is named as myapp rather than the demo project TestGcm, right?

My app still crashes after that though:

Does it mean after clicking notification the app launches and crashed?

from react-native-gcm-android.

 avatar commented on July 19, 2024

I see you added 0.1.12. I tested the app with this and the messages inside the app work! They now get properly console logged, even when I reload the JS afterwards and send a new notification.

Basically everything works now, except that the app still crashes after I receive a notification (when the app is closed and not running in the background).

The notification and the error dialog pop up at the same time. I can dismiss the dialog, click the notification and the app starts properly. It's only the dialog showing up what's the problem now.

You're correct that I'm running this in my own app instead of the TestGcm app. If you want, I can test it and see if that one also crashes for me?

from react-native-gcm-android.

oney avatar oney commented on July 19, 2024

Good!

Basically everything works now, except that the app still crashes after I receive a notification (when the app is closed and not running in the background).

About above issue, react native version of myapp app is 0.17.0, right?

from react-native-gcm-android.

 avatar commented on July 19, 2024

That's correct!

I'm using the following node modules now:

"react-native": "0.17.0",
"react-native-gcm-android": "^0.1.2",
"react-native-system-notification": "0.0.7"

from react-native-gcm-android.

oney avatar oney commented on July 19, 2024

Just update 0.1.3 to npm. It should work on react native 0.17.0.
Please confirm that 5 situations are working.

  • The app is foreground
  • The app is background and alive
  • The app is closed
  • Clicking notification will open the app
  • Reload JS works too.

Thanks!

from react-native-gcm-android.

 avatar commented on July 19, 2024

You are awesome! Everything works.

Notification when the app is in the foreground
Works - Logs the notification. isForGround = true

Notification when the app is in the background and alive
Shows the notification in my status bar. Also logs it: isForGround = false

Notification when app is closed
Shows the notification in my status bar.

Clicking notification will open the app
Works.

Reload JS and send notifications
Works.

One bug (it's a far fetched one)

  • Make sure the app is closed
  • Send notification
  • Click notification
  • Now close the app but let it run in the background
  • Send notification
  • Click notification so the app opens again
  • While the app is open: send another notification

Results in isForGround = false, even though the app is running.

from react-native-gcm-android.

oney avatar oney commented on July 19, 2024

0.1.5 should solve it. Please try it!

from react-native-gcm-android.

 avatar commented on July 19, 2024

Heyo.

Sorry for my late reply!

A use case like that would be extremely rare for my app, but perhaps other people will profit from it. Thanks for taking a look at it.

I just tested it and it does not seem to work yet. I followed the exact same steps, and I end up with GcmAndroid.isInForeground = false

This is with version 0.1.6 and react-native 0.17.0

from react-native-gcm-android.

xphaul avatar xphaul commented on July 19, 2024

@oney i am experiencing this issue . it seems that if(!GcmAndroid.isInForeground) is not firing when app received a notification from and its state is on background . It is fine when the app is running . i can click the notifications

from react-native-gcm-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.