Har*_*jan 5 android firebase ionic-framework
我正在使用以下代码向设备发送推送通知。
var nTitle = "New message from " + $rootScope.clients_firstName;
var to = "DeviceToken is here";
var notification = {
'title': nTitle,
//'body': 'Click here to more details...',
'icon': 'firebase-logo.png',
'click_action': 'openapp'
};
var key = 'your key';
fetch('https://fcm.googleapis.com/fcm/send', {
'method': 'POST',
'headers': {
'Authorization': 'key=' + key,
'Content-Type': 'application/json'
},
'body': JSON.stringify({
'notification': data,
'to': to
})
}).then(function(response) {
//console.log("res ", response);
}).catch(function(error) {
console.error("err ", error);
});
Run Code Online (Sandbox Code Playgroud)
推送通知在设备上成功发送。
但是,当我单击通知时,应打开特定页面。
例如 'click_action' : 'openapp/somepage'
然后,当我单击pushnotification时,应该打开“ somepage”。
AndroidManifest.xml
<activity android:name="MainActivity" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="openapp" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
我的项目结构
--platforms
--plugins
--www
--app
--about
--about.html
--about.ctrl.js
--product
--product.html
--product.ctrl.js
--css
--js
--lib
index.html
Run Code Online (Sandbox Code Playgroud)
如果我单击通知并且想要打开产品或关于页面,那么我该怎么办?
怎么了 请告诉我正确的解决方案。
我知道你问的是 Ionic 1。但我只知道 Ionic 2。希望这对你有帮助。
我认为您应该在通知的附加数据部分添加有关您需要打开哪个页面的信息。像这样的东西:
'body': JSON.stringify({
'notification': data,
'to': to,
'data' : {
'action' : 'Needed page'
}
})
Run Code Online (Sandbox Code Playgroud)
然后你应该在 subscribe 方法上捕获它。像这样的东西:
fcm.onNotification().subscribe(data=>{
console.log("data", data);
if (data['action'] && data['action'] == 'Needed page'){
this.navCtrl.push('Needed page'); //Use Navigation controller to open needed page
}
})
Run Code Online (Sandbox Code Playgroud)
对于本机 cordova FCM 插件:
FCMPlugin.onNotification(function(data){
console.log("data", data);
if (data['action'] && data['action'] == 'Needed page'){
this.navCtrl.push('Needed page'); //Use Navigation controller to open needed page
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3175 次 |
| 最近记录: |