0

我正在使用休息 API 发送百度推送通知。我无权访问 Android 的通知生成器类,所以我不能,例如,使用notificationBuilder.setPriority(2);. 我真正需要知道的主要事情是如何将百度推送通知的优先级设置为 MAX,仅使用 JSON。

根据这个网站,这里是百度 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 对应的通知。

4

1 回答 1

0

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

在客户端应用中,需要设置通知生成器,并给它一个id,像这样(注意我用Xamarin Forms的是在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()方法中的第二个参数相对应。

于 2017-03-04T04:59:41.653 回答