Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I manipulate the data obtained? #14

Open
jecorrales3 opened this issue Sep 30, 2019 · 4 comments
Open

How can I manipulate the data obtained? #14

jecorrales3 opened this issue Sep 30, 2019 · 4 comments

Comments

@jecorrales3
Copy link

I am here because I am trying to manipulate the information obtained from the plugin, but I have reached an obstacle where I cannot handle or push the JSON data I need, such as the title and the text, to an array.

Sorry for closing the previous problem but I was wrong user.

I am using IONIC 5 and I can say that it works correctly by displaying notifications as follows

constructor(public navCtrl: NavController) {

    this.setNotificationListenerCallback();

  }

  setNotificationListenerCallback(){
    notificationListener.listen(function(n){
      alert("Received notification " + JSON.stringify(n) );
    }, function(e){
      setTimeout(this.setNotificationListenerCallback, 1000);
      alert("Notification Error " + e);
    });
  }

But if I try to push the data obtained to an arrangement, it does not generate any action. Simply, it is blank, which does not allow us to move forward because I need to list the notifications in my Ionic application and thus generate the history of it.

Can someone help me or if what I need is possible?

Thanks!

@rephus
Copy link
Member

rephus commented Sep 30, 2019

I'm sorry but I'm not famliar with IONIC 5, so I'm not sure what you need to do to get your notification.
Have you tried to log the notification (Log.d) json on notificationListener.listen ? Is this empty ? is the alert a method from IONIC 5 ? Can you push a simple harcoded string into IONIC 5 correctly ?

@jecorrales3
Copy link
Author

Hi, regards. Yes, all it's working good but if I try to send the data or push it in a array or set it for a local storage and it doesnt send the data, this is how I'm trying to solve:

var array    = [];
    var contacts = [];
    notificationListener.listen(function(n)
    {
      var json  = JSON.stringify(n);

      array.push(n);
      for(var i = 0; i < array.length; i++)
      {
        var item = array[i];
        if (item.package == 'com.whatsapp')
        {
            //localStorage.setItem("contacts_data", json);
            //alert("Message: " + json)
            this.contacts_wapp.push({
                  "number": '233 3323 323',
                  "texto': 'Testing message'
            });
        }
      }
    },
    function(e)
    {
      setTimeout(this.setNotificationListenerCallback, 1000);
      alert("Notification Error " + e);
    });

Thanks for your answer, this is Angular for Ionic... finally is javascript

@ashu-lt
Copy link

ashu-lt commented Nov 27, 2019

Have anyone found the solution for manipulating the data in notificationListener?? the above solution is not working

@jecorrales3
Copy link
Author

@ashu8911 sorry but I couldn't find a really solution for this, so I had to move on to develop in native (Android Studio). I spend a lot of time trying to solve this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants