自定义Baidu推JSON有效载荷



我正在使用REST API发送BAIDU推送通知。我无法访问Android的通知构建器类,因此我不能使用notificationBuilder.setPriority(2);。实际上,我需要知道的主要内容是如何将Baidu推送通知的优先级设置为Max,仅使用JSON。

根据此网站,以下是Baidu JSON有效载荷的所有键和值:

{
    //android必选,ios可选
    "title": "hello" ,   
    "description": "hello world" 
    //android特有字段,可选
    "notification_builder_id": 0,
    "notification_basic_style": 7,
    "open_type":0,
    "net_support" : 1,
    "user_confirm": 0,
    "url": "http://developer.baidu.com",
    "pkg_content":"",
    "pkg_name" : "com.baidu.bccsclient",
    "pkg_version":"0.1",
    //android自定义字段
    "custom_content": {
        "key1":"value1", 
        "key2":"value2"
    },  
    //ios特有字段,可选
    "aps": {
        "alert":"Message From Baidu Push",
       "sound":"",
        "badge":0
    },
    //ios的自定义字段
    "key1":"value1", 
    "key2":"value2"
}

我假设我需要设置notification_builder_id的值,但是由于它仅将整数作为一个值,所以我不确定如何创建通知以与ID相对应。

我能够找出如何将优先级设置为高,以使通知显示为横幅,而不是状态栏中的图标。

在客户端应用中,您需要设置通知构建器,然后给它一个ID(请注意我使用的是Xamarin Forms,但是如果您使用的是本机Android,则逻辑是相同的。此外,此代码应在PushManager.StartWork()方法调用之后直接放置,最有可能在您的活动的onCreate()方法中放置):

BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder();
builder.SetNotificationFlags(
    (int)NotificationFlags.AutoCancel |
    (int)NotificationFlags.HighPriority |
    (int)NotificationFlags.ShowLights);
builder.SetNotificationDefaults(
    (int)NotificationDefaults.Lights |
    (int)NotificationDefaults.Vibrate);
builder.SetStatusbarIcon(Resource.Drawable.icon);
// the second parameter is the id. This is the id that you need to set
// in the JSON payload in order for the incoming notification to appear
// in this way.
PushManager.SetNotificationBuilder(Xamarin.Forms.Forms.Context, 1, builder);

,然后是有效载荷,就像这样:

{"title":"My Title","description":"my description","notification_builder_id":1}

再次请注意,Notification_builder_id的值必须与SetNotificationBuilder()方法中的第二个参数相对应。

最新更新