ionic中的android推送通知

ionic中的android推送通知,android,ionic,Android,Ionic,我正在使用ionic framework开发移动应用程序。我已经成功实现了推送通知。当我单击我想要的通知时,它应该出现在特定页面上。我将如何做到这一点? 在客户端: var user = $ionicUser.get(); if(!user.user_id) { // Set your user_id here, or generate a random one. user.user_id = $ionicUser.generateGUID(); };

我正在使用ionic framework开发移动应用程序。我已经成功实现了推送通知。当我单击我想要的通知时,它应该出现在特定页面上。我将如何做到这一点? 在客户端:

 var user = $ionicUser.get();
     if(!user.user_id) {
     // Set your user_id here, or generate a random one.
     user.user_id = $ionicUser.generateGUID();
     };


     // Identify your user with the Ionic User Service
     $ionicUser.identify(user).then(function(){
     //$scope.identified = true;
     //alert('User ID ' + user.user_id);
     //alert("here");
     $ionicPush.register({
      canShowAlert: true, //Can pushes show an alert on your screen?
      canSetBadge: true, //Can pushes update app icon badges?
      canPlaySound: true, //Can notifications play a sound?
      canRunActionsOnWake: true, //Can run actions outside the app,
      onNotification: function(notification) {

        // Handle new push notifications here
        // console.log(notification);
        return true;
      }
     });
     });



  });
})

.config(['$ionicAppProvider', function($ionicAppProvider) {
  $ionicAppProvider.identify({
    app_id: 'xxxxxxxxxxxxx',
    api_key: 'xxxxxxxxxxxxxx',
    dev_push: false
  });
}])
在服务器端,我使用了php:

$deviceToken = 'APA91bHKwBKrIjmmZ9lke97fl_GbOQ9iRRo-S2sNnZp085hPqVaTHMOd0wqhYFF1PtrtOzFrETX7ZNIkU0JDhC49Tby_AEFIQFRX99B0QpZd7xdiTqsP6sZ08P-8ESdJAie5AJNxhW89nQ7S9evZNcAc9tsJaG91Xw';

$registrationIds = explode(",",$deviceToken);

//$registrationIds = array($deviceToken);

// prep the bundle

$msg = array

(

    'notId' => time(),

    'message'       => 'Technovault is awesome!!!',

    'title'         => 'Title',

    'smallIcon'     =>'icon'



);

$fields = array

(

    'registration_ids'  => $registrationIds,

    'data'              => $msg

);

$headers = array

(

    'Authorization: key=' . 'xxxxxxxxxx',

    'Content-Type: application/json'

);

$ch = curl_init();

curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );

curl_setopt( $ch,CURLOPT_POST, true );

curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );

curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );

curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );

curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );

$result = curl_exec($ch );

curl_close( $ch );

echo $result;

}

else {

    echo "Error";

}

几天前我解决了一个类似的问题。我有一个包含文章列表和文章详细信息的应用程序。当有新文章时,服务器会发送通知,而不是将文章id包含在播放负载中

当应用程序收到通知时,我将其保存在localStorage中,当用户单击通知时,通过resume事件,我可以读取此localStorage项目并更改应用程序的状态,并显示此文章id的文章控制器视图

我没有使用ionPush库,我使用了Cordova PushPlugin,因为我有一个定制的推送通知服务器

应用程序收到通知时:

$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
   if (ionic.Platform.isAndroid() && notification.event == 'message') {
        var newsid=notification.payload.newsid;
        if (typeof newsid != 'undefined') {
            // save the newsid to read it later in the resume event
            $window.localStorage.setItem('goafterpush',newsid);
        }
    }
});
恢复活动:


我希望这段代码能帮助您。

几天前我解决了一个类似的问题。我有一个包含文章列表和文章详细信息的应用程序。当有新文章时,服务器会发送通知,而不是将文章id包含在播放负载中

当应用程序收到通知时,我将其保存在localStorage中,当用户单击通知时,通过resume事件,我可以读取此localStorage项目并更改应用程序的状态,并显示此文章id的文章控制器视图

我没有使用ionPush库,我使用了Cordova PushPlugin,因为我有一个定制的推送通知服务器

应用程序收到通知时:

$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
   if (ionic.Platform.isAndroid() && notification.event == 'message') {
        var newsid=notification.payload.newsid;
        if (typeof newsid != 'undefined') {
            // save the newsid to read it later in the resume event
            $window.localStorage.setItem('goafterpush',newsid);
        }
    }
});
恢复活动:


我希望这段代码能对您有所帮助。

我已经为Android和iOS开发了这段代码,在python中,我已经用state name和Id参数设置了有效负载

payload = {"$state":"state.name", "$stateParams": "{\"id\": \""+time()+"\"}"}
然后我把它和其他所有的信息一起放进去

"payload": payload

这应该发生在您的$msg数组中,就是这样,当用户单击应用程序打开的通知并使用提供的参数进入定义的状态时。

我已经为Android和iOS提供了此功能,在python中,我已经使用状态名称和Id参数设置了有效负载

payload = {"$state":"state.name", "$stateParams": "{\"id\": \""+time()+"\"}"}
然后我把它和其他所有的信息一起放进去

"payload": payload

当用户单击应用程序打开的通知并使用提供的参数进入定义状态时,这应该发生在$msg数组中。在客户端收到的通知与参数相关。当您点击通知进入应用程序时,它的值将为
false
。因此,这就是您执行特定操作的方式:

onNotification: function(notification) {
                  if(notification.foreground == false){
                    //add your logic here to navigate to other page
                  }
                }

您在客户端收到的通知
具有关联的参数
前台
。当您点击通知进入应用程序时,它的值将为
false
。因此,这就是您执行特定操作的方式:

onNotification: function(notification) {
                  if(notification.foreground == false){
                    //add your logic here to navigate to other page
                  }
                }

请使用您的代码更新您的问题。请使用您的代码更新您的问题。您好,我仍然不知道解决方案…我正在使用节点服务器,我将负载像这样放在我的服务器中:“通知”:{“警报”:message.message,“ios”:{“badge”:1,“负载”:{“taskId”:message.relatedTask},但我不知道如何在我的客户端中读取我的taskId有效负载。您将如何在onNotification回调中读取有效负载?@hughou如果您使用的是不推荐使用的旧插件,则可以通过以下方式在客户端的notification对象上访问taskId
notification.payload.taskId
。但是如果您使用的是最新插件,则
notification.additionalData.taskId
。您好,我仍然不知道解决方案…我正在使用节点服务器,我将负载像这样放在我的服务器中:“通知”:{“警报”:message.message,“ios”:{“徽章”:1,“负载”:{“taskId”:message.relatedTask},但我不知道如何在我的客户端中读取我的taskId有效负载。您将如何在onNotification回调中读取有效负载?@hughou如果您使用的是不推荐使用的旧插件,则可以通过以下方式在客户端的notification对象上访问taskId
notification.payload.taskId
。但是如果您使用的是最新插件,则
notification.additionalData.taskId