Git Product home page Git Product logo

Comments (5)

jlugner avatar jlugner commented on July 19, 2024

This only seems to happen when I import AppState from react-native in the same file as my notification-code. Any ideas here?

from react-native-gcm-android.

udfalkso avatar udfalkso commented on July 19, 2024

I just wrote about a possible workaround here: #51 (comment)

from react-native-gcm-android.

savioseb avatar savioseb commented on July 19, 2024

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.

RonakKhandelwal avatar RonakKhandelwal commented on July 19, 2024

@savioseb It still crashes!! any possible workaround?

from react-native-gcm-android.

chansila avatar chansila commented on July 19, 2024

As @udfalkso mentioned I have rewrite his code for workaround to get notification dynamically from GCM itself.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    Bundle bundle = intent.getBundleExtra("bundle");
    Object result = bundle.get("info");
    String data   = result.toString();
    String id     = bundle.get("google.message_id").toString();
    try{
        JSONObject jsonObj = new JSONObject(data);
        Log.d(TAG,"onStartCommand jsonObj => :"+jsonObj);
        Log.d(TAG,"onStartCommand bundle => :"+bundle);
        String message = jsonObj.getString("message");
        String subject = jsonObj.getString("subject");
        Integer notificationId = Integer.parseInt(id.substring(0, 10).replaceAll("[\\D]", ""));

        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 = message;
        attributes.subject = subject;
        Notification notification = new Notification(this, notificationId, attributes);
        notification.create();

    }catch (JSONException e) {
       Log.d(TAG,e);
    }  
    return START_NOT_STICKY;
}

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.