NativeScript / push-plugin

Contains the source code for the Push Plugin.
Apache License 2.0
123 stars 48 forks source link

Using a callback after clicking the notification on Android #212

Closed tomshabtay closed 6 years ago

tomshabtay commented 6 years ago

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

i used this code in order to get the notification from the intent like in the documentation:

        application.on(application.resumeEvent, function (args) {
            if (args.android) {
                var act = args.android;
                var intent = act.getIntent();
                var extras = intent.getExtras();

                if (extras) {
                    // console.dir(extras)
                    console.log(extras.keySet().toString());
                    for (var key in extras) {
                        console.log(key + ' --> ' + extras[key]);
...

instead of seeing keys related to the notification in the logs i see a list of methods:

JS: android.util.MapCollections$KeySet@cf2feb2f
JS: constructor --> function () { [native code] }
JS: <init> --> function <init>() { [native code] }
JS: clear --> function clear() { [native code] }
JS: clone --> function clone() { [native code] }
JS: describeContents --> function describeContents() { [native code] }
JS: getBinder --> function getBinder() { [native code] }
JS: getBundle --> function getBundle() { [native code] }
JS: getByte --> function getByte() { [native code] }
JS: getByteArray --> function getByteArray() { [native code] }
JS: getChar --> function getChar() { [native code] }
JS: getCharArray --> function getCharArray() { [native code] }
JS: getCharSequence --> function getCharSequence() { [native code] }
JS: getCharSequenceArray --> function getCharSequenceArray() { [native code] }
JS: getCharSequenceArrayList --> function getCharSequenceArrayList() { [native code] }
JS: getClassLoader --> function getClassLoader() { [native code] }
JS: getFloat --> function getFloat() { [native code] }
JS: getFloatArray --> function getFloatArray() { [native code] }
...

Is it what i'm supposed to see or something in my implementation isn't right?

Thanks, Tom

tomshabtay commented 6 years ago

I managed to fix it by using this code from the demo app.


        application.on(application.resumeEvent, function (args) {
            if (args.android) {
                const act = args.android;
                const intent = act.getIntent();
                const extras = intent.getExtras();
                console.log("Resuming activity");
                if (extras) {
                    console.log("If your notification has data (key: value) pairs, they will be listed here:");
                    const keys = extras.keySet();
                    const iterator = keys.iterator();
                    while (iterator.hasNext()) {
                        const key = iterator.next();
                        console.log(key + ": " + extras.get(key).toString());
                        // clear the used keys in order to avoid getting them back
                        // when manually switching the application between background and foreground
                        intent.removeExtra(key);
                    }
                }
            }
        });
zbranzov commented 6 years ago

If you managed to fix the case would you close the issue?