Ejaz Mafat Ejaz Mafat - 5 months ago 56
Android Question

Cordova Android Push Notification With Action Button

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..

Answer

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.

Comments