简体   繁体   English

Cordova Android带操作按钮的推送通知

[英]Cordova Android Push Notification With Action Button

I have used Push Plugin , when i am sending push with action button 1)accept 2)ignore. 我在使用操作按钮1)接受2)忽略发送按钮时使用了Push Plugin

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.. 在代码“ app.onPushAccept”函数中,是“ accept”按钮的回调。

Please help me as soon as possible. 请尽快帮助我。 Thank You.. 谢谢..

Android Push Notification (Only) Android推送通知(仅)

Step 1 - First of all go to given below directory 步骤1-首先转到以下目录

     plugins > phonegap-plugin-push > src > android > com > adobe > phonegap > push

Step 2 - Open GCMIntentService.java File from above directory 第2步-从上述目录中打开GCMIntentService.java文件

Step 3 - Determine function calling "createActions" and Add actual parameter "requestCode" like... 第3步-确定调用“ createActions”的函数,并添加实际参数“ requestCode”,例如...

     createActions(extras,mBuilder,resources,packageName,notId,requestCode);

Step 4 - Determine function definition "createActions" and Add formal parameter "int requestCode" like... 步骤4-确定函数定义“ createActions”,并添加形式参数“ int requestCode”,例如...

     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... 步骤5-在函数定义“ createActions”和for循环内部将第二个参数从“ i”更改为“ requestCode”,例如...

     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. 步骤6-完成上述所有步骤后,请删除android平台(如果已添加平台),然后添加android平台。

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: 因此,现在您有两个选择,您可以将某些内容放入推式有效载荷中,以唯一地标识将接收到的将被放入data.additionalData中的推式,或修改回调以调用另一个事件处理程序:

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

Use navigator.notification.confirm method of the plugin cordova-plugin-dialogs 使用插件cordova-plugin-dialogs的 navigator.notification.confirm方法

it displays a customizable confirmation dialog box. 它显示一个可自定义的确认对话框。

Syntax 句法

navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels])
  • message : Dialog message. 消息 :对话框消息。 (String) (串)
  • confirmCallback : Callback to invoke with index of button pressed (1, 2, or 3) or when the dialog is dismissed without a button press (0). confirmCallback :使用按下的按钮索引(1、2或3)或在没有按下按钮的情况下关闭对话框时调用的回调。 (Function) (功能)
  • title : Dialog title. title :对话框标题。 (String) (Optional, defaults to Confirm) (字符串)(可选,默认为确认)
  • buttonLabels : Array of strings specifying button labels. buttonLabels :指定按钮标签的字符串数组。 (Array) (Optional, defaults to [OK,Cancel]) (数组)(可选,默认为[确定,取消])

you can change buttonLabels to ["Accept","Ignore"] to satisfy your needs. 您可以将buttonLabels更改为[“ Accept”,“ Ignore”],以满足您的需求。

Example

function onConfirm(buttonIndex) {
    alert('You selected button ' + buttonIndex);
}

navigator.notification.confirm(
    'You are the winner!', // message
     onConfirm,            // callback to invoke with index of button pressed
    'Game Over',           // title
    ['Accept','Ignore']     // buttonLabels
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM