Skip to content
This repository was archived by the owner on Feb 7, 2019. It is now read-only.
This repository was archived by the owner on Feb 7, 2019. It is now read-only.

Using a callback after clicking the notification on Android #212

Closed

Description

@tomshabtay

Which platform(s) does your issue occur on?

  • Android 7.1.1
  • emulator: Nexus

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

  • CLI: 3.4.3

  • Cross-platform modules: 3.4.1

  • Runtime(s):
    tns-ios version: "3.4.1"
    tns-android version": "3.4.2"

  • Plugin(s):

"dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/platform-server": "^5.0.0",
    "@angular/router": "^5.0.0",
    "nativescript-angular": "^5.2.0",
    "nativescript-angular-snapshot": "3.0.0-5.5.372.32",
    "nativescript-animatecss": "^1.0.0",
    "nativescript-dom": "^1.0.8",
    "nativescript-floatingactionbutton": "^3.0.1",
    "nativescript-globalevents": "^1.1.0",
    "nativescript-loading-indicator": "^2.3.2",
    "nativescript-ngx-fonticon": "^4.0.0",
    "nativescript-push-notifications": "^1.1.2",
    "nativescript-screen-orientation": "^2.0.0",
    "nativescript-theme-core": "1.0.4",
    "nativescript-ui-listview": "^3.5.1",
    "reflect-metadata": "~0.1.8",
    "rxjs": "^5.5.2",
    "tns-core-modules": "^3.4.1"
  },
  "devDependencies": {
    "babel-traverse": "6.4.5",
    "babel-types": "6.4.5",
    "babylon": "6.4.5",
    "lazy": "1.0.11",
    "nativescript-dev-android-snapshot": "^0.*.*",
    "nativescript-dev-typescript": "^0.4.4",
    "typescript": "^2.4.2",
    "zone.js": "~0.8.2"
  }

Please, tell us how to recreate the issue in as much detail as possible.

I am trying to invoke a callback function after the notification is been clicked (and the app is on background).

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

Activity

  1. tomshabtay commented on Apr 16, 2018

    @tomshabtay
    Author

    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);
                        }
                    }
                }
            });
    
  2. zbranzov commented on Apr 20, 2018

    @zbranzov
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions