2017-03-04 5 views
0

Baidu Push 알림을 보내기 위해 나머지 API를 사용하고 있습니다. Android의 알림 빌더 클래스에 액세스 할 수 없으므로 예를 들어 notificationBuilder.setPriority(2);을 사용할 수 없습니다. 정말 알아야 할 중요한 점은 JSON 만 사용하여 Baidu Push 알림의 우선 순위를 MAX로 설정하는 방법입니다. this website에 따르면Baidu Push JSON 페이로드 사용자 정의

, 여기에 바이 JSON 페이로드의 키와 값의 모두 : 나는 notification_builder_id의 값을 설정해야 가정

{ 
    //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" 
} 

는하지만 단순히는 AS 정수를 걸립니다 가치, 나는 ID와 일치하는 알림을 만드는 방법을 모르겠습니다.

답변

0

상태 표시 줄에있는 아이콘과는 달리 알림을 배너로 표시하기 위해 우선 순위를 높음으로 설정하는 방법을 알 수있었습니다.

클라이언트 응용 프로그램에서 알림 빌더를 설정하고 ID를 부여해야합니다 (예 : Xamarin Forms을 사용하고 있지만 기본 Android를 사용하는 경우 로직이 동일 함). 코드) 활동의 onCreate() 방법으로 대부분의 PushManager.StartWork() 메서드 호출 바로 뒤에 위치해야합니다 : 다음

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_buil 값 der_id는 SetNotificationBuilder() 메소드의 두 번째 매개 변수와 일치해야합니다.