Comments (16)
Re: onPause()
, React Native changed some signatures in facebook/react-native@19a1c4c#diff-dc0f3a09c238b372cb1c27aa5f7dcbce. I pointed this plugin to RN 0.24.1 (the one I'm using), changed the calls to onPause()
and onDestroy()
, and things seem to be working so far - however, I haven't done a thorough inspection for any remaining dependencies on 0.17.+.
build.gradle:
// add below
allprojects {
repositories {
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "../../../node_modules/react-native/android"
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.facebook.react:react-native:0.24.+' // change from 0.17.+
compile 'com.google.android.gms:play-services-gcm:8.1.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile project(':react-native-system-notification')
}
BackgroundService.java:
mReactInstanceManager.onHostPause(); // change from onPause
mReactInstanceManager.destroy(); // change from onDestroy
from react-native-gcm-android.
I didn't get this error, but I believe this is probably the same issue as the others are having. The way this lib is written, it's trying to instantiate the entire react app when receiving a background notification and some of the native modules (in my case FBSDK caused most of the issues) just won't instantiate nicely in this scenario for some reason.
For most use cases, this is probably overkill. I ended up writing a very minimal background service that just shows the text of the notification via the react-native-system-notification lib and nothing more. This workaround may help you as well.
First remove com.oney.gcm from this line in your Manifest:
<service android:name=".BackgroundService"></service>
Now add BackgroundService.java to your project:
package com.myapp;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import io.neson.react.notification.NotificationAttributes;
import android.os.Bundle;
import io.neson.react.notification.Notification;
public class BackgroundService extends Service {
private static final String TAG = "BackgroundService";
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "onStartCommand");
Bundle bundle = intent.getBundleExtra("bundle");
String body = bundle.getString("gcm.notification.body", "You have a notification");
String subject = bundle.getString("gcm.notification.subject", "MyApp Title");
NotificationAttributes attributes = new NotificationAttributes();
attributes.delayed = false;
attributes.scheduled = false;
attributes.autoClear = true;
attributes.inboxStyle = false;
attributes.priority = 2;
attributes.sound = "default";
attributes.smallIcon = "ic_launcher";
attributes.message = body;
attributes.subject = subject;
Notification notification = new Notification(this, 1, attributes);
notification.create();
return START_NOT_STICKY;
}
}
from react-native-gcm-android.
Hmm, I think these may be different issues though. I have gotten other errors similar to #54.
I had to rearrange my client entry js to ensure none of my App would be imported or registered if we were receiving a notification. Like this:
'use strict'
import React from 'react-native'
import GcmAndroid from 'react-native-gcm-android'
import Notification from 'react-native-system-notification'
if (GcmAndroid.launchNotification) {
Notification.create({
subject: GcmAndroid.launchNotification.title,
message: GcmAndroid.launchNotification.body,
})
GcmAndroid.stopService()
} else {
//We don't want the app loading up as normal when the app receives
//a notification. So we only load this when the app launches as normal.
const App = require('./containers/App').default
React.AppRegistry.registerComponent('WhyWait', () => App)
}
from react-native-gcm-android.
I get this same error. The notification does appear, and can be clicked on. But the app crashes in the background. The result of this is that you cannot receive a follow up notification until the user launches/closes the app again.
[email protected]
[email protected]
[email protected]
from react-native-gcm-android.
@stinju Can you elaborate a little more, I tried changing those but my build failed with
/Users/pete/Code/Play/React-Native/Awesome/node_modules/react-native-gcm-android/android/src/main/java/com/oney/gcm/BackgroundService.java:47: error: cannot find symbol mReactInstanceManager.onHostPause(); ^ symbol: method onHostPause() location: variable mReactInstanceManager of type ReactInstanceManager /Users/pete/Code/Play/React-Native/Awesome/node_modules/react-native-gcm-android/android/src/main/java/com/oney/gcm/BackgroundService.java:48: error: cannot find symbol mReactInstanceManager.destroy(); ^ symbol: method destroy() location: variable mReactInstanceManager of type ReactInstanceManager 2 errors
from react-native-gcm-android.
@peterlazar1993 were you able to resolve your issue? Looks like your build wasn't compiling against an RN version with the new signatures. Check to see if the 'onHostPause' method is implemented in ReactInstanceManager.java
in your RN version. If so, then you might need to fiddle with the changes I mentioned above to get your build to use your RN version for this package. BTW, I wasn't clear above, but the build.gradle
file mentioned is the one for react-native-gcm-android, not the one for your project/app.
from react-native-gcm-android.
Did you resolve this already? How did you solve this issue?
from react-native-gcm-android.
@jojonarte We decided to write a custom BackgroundService
from react-native-gcm-android.
I resolved this error by creating a fork where removed not existing methods. And another thing is you should not require whole App while in background service, I'm not sure why, but maybe because some environment is not initialised.
from react-native-gcm-android.
@vmakhaev What kind of background service did you write? Care to share?
from react-native-gcm-android.
@peterlazar1993 I used the one from react-native-gcm-android
from react-native-gcm-android.
Comment the
GcmAndroid.stopService();
line.
It should work.
My index.android.js snippet:
`
if (GcmAndroid.launchNotification) {
console.log('Before entering function:', GcmAndroid.launchNotification);
//GcmAndroid.stopService();
console.log('GcmAndroid.launchNotification:', GcmAndroid.launchNotification);
var notification = GcmAndroid.launchNotification;
var info = JSON.parse(notification.info);
Notification.create({
subject: info.subject,
message: info.message,
});
//GcmAndroid.stopService();
} else {
class Savio extends Component {
`
from react-native-gcm-android.
#22 also addressed by doing this change.
from react-native-gcm-android.
@udfalkso Your solution works, but there's any way to make it show the message received by an external API instead of a static one??
from react-native-gcm-android.
@samcarlosimpres Yes. The code fetches the message from the notification, the static string there is just a fallback.
For me the value is coming through in the "gcm.notification.body" key of the bundle, perhaps for you it is at another key.
bundle.getString("gcm.notification.body", "You have a notification");
from react-native-gcm-android.
guys, sorry.
But how to receive notification when app is fully closed on Android?
from react-native-gcm-android.
Related Issues (20)
- npm version is newer than github version HOT 1
- App crashes when closed while receiving notification HOT 5
- npm WARN [email protected] requires a peer of react-native-system-notification@^0.1.2 but none was installed. HOT 7
- Error: 'GcmAndroid.launchNotification internal', undefined HOT 1
- Handling AndroidManifest.xml with buildtypes and applicationIdSuffix HOT 1
- com.facebook.react.bridge.UnexpectedNativeTypeException: TypeError: expected dynamic type `int64', but had type `double'
- issue with implementaion HOT 2
- App does not receive messages after reboot on Android 5.0 HOT 1
- App crashes while in background
- Cant get token HOT 1
- RN 0.29 needs Activity instance? HOT 3
- Emitter
- SysNotificationClick as Listener doesn´t work for me (Android)
- Oney: Are you still interested in keeping this library up to date? I can help HOT 1
- Error :app:transformClassesWithJarMeringForDebug HOT 1
- google services
- No static method builder() Lcom/facebook/react/ReactInstanceManager$Builder; HOT 1
- I'm getting this error when I run my app. No error shows up while building though. Please help me
- react-native-fcm
- ar
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-gcm-android.