I have used Push Plugin , when i am sending push with action button 1)accept 2)ignore.
when notification came , i was clicked on "accept" button . but i want parameters with the "accept" button callback. from that i will identify with notification's "accept" was called.
code reference
//initialization of push object
var push = PushNotification.init({
"android": {
"alert": "true",
"senderID": CONFIG.PROJECT_NUMBER,
"icon": "img/ionic.png",
"iconColor": "blue",
"badge": "true"
},
"ios": {
"alert": "true",
"badge": "true",
"sound": "true"
},
"windows": {
}
});
//listner for getting registration detail of device
push.on('registration', function(data) {
device_id_for_push=data.registrationId;
});
//listner called on new push notification
push.on('notification', function(data) {
// app.onPushAccept(data);
alert("on notification");
alert(JSON.stringify(data));
});
//error listner
push.on('error', function(e) {
// alert(e);
// alert("push error");
});
app.onPushAccept=function(data){
alert("onPushAccept")
alert(JSON.stringify(data));
// cordova.plugins.notification.badge.clear();
// cordova.plugins.notification.badge.increase();
}
in code "app.onPushAccept" function is callback of "accept" button..
Please help me as soon as possible. Thank You..
Android Push Notification (Only)
Step 1 - First of all go to given below directory
plugins > phonegap-plugin-push > src > android > com > adobe > phonegap > push
Step 2 - Open GCMIntentService.java File from above directory
Step 3 - Determine function calling "createActions" and Add actual parameter "requestCode" like...
createActions(extras,mBuilder,resources,packageName,notId,requestCode);
Step 4 - Determine function definition "createActions" and Add formal parameter "int requestCode" like...
private void createActions(Bundle extras, NotificationCompat.Builder mBuilder, Resources resources, String packageName, int notId,int requestCode)
Step 5 - In function definition "createActions" and inside for loops Change second parameter from "i" to "requestCode" like...
pIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
pIntent = PendingIntent.getBroadcast(this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Step 6 - After completing above all steps remove android platform if already added platform Then add android platform.
Sorry and improve if any mistake founds in my solution.
Okay, first imagine you are sending the following payload:
{
"registration_ids": ["my device id"],
"data": {
"title": "My title",
"message": "My message.",
"actions": [
{ "title": "Accept", "callback": "app.accept", "foreground": true},
{ "title": "Ignore", "callback": "app.ignore", "foreground": false}
]
}
}
and you have setup the following action button handlers:
app.accept = function(data} {
// do something
}
app.ignore = function(data} {
// do something
}
so now you have two options you can either put something in the push payload that uniquely identifies the push that was received which will be put in data.additionalData or modify the callbacks to call another event handler:
app.accept = function(data} {
app.processPush('accept', data);
}
app.ignore = function(data} {
app.processPush('ignore', data);
}
app.processPush = function(type, data) {
if (type === 'accept') {
// do accept stuff
} else if (type === 'ignore') {
// do ignore stuff
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With