2015-07-15 20 views
8

Tôi đã tích hợp Urban Airship SDK vào ứng dụng của mình trên thiết bị với Android 4.2 (Jelly Bean). Tôi đã nhận được thông báo đẩy chung. Được rồi. Nhưng tôi muốn nhận thông báo đẩy tương tác bằng nút "Lưu".Làm thế nào để có được thông báo tương tác đẩy với Urban Airship trong Android?

phụ thuộc của tôi từ build.gradle:

dependencies { 
    compile 'com.google.code.gson:gson:2.2.4' 
    compile 'com.google.android.gms:play-services:+' 

    compile project (':urbanairship-lib-6.1.1') 
    compile 'com.android.support:support-v4:22.2.0' 

    // Recommended for in-app messaging 
    compile 'com.android.support:cardview-v7:22.2.0' 

    // Recommended for location services 
    compile 'com.google.android.gms:play-services-location:7.5.0' 

    // Required for Android (GCM) push notifications 
    compile 'com.google.android.gms:play-services-gcm:7.5.0' 

    compile files('libs/commons-io-2.4.jar') 
    compile files('libs/FlurryAnalytics-4.1.0.jar') 
    compile files('libs/nineoldandroids-2.4.0.jar') 
} 

Theo official documentation, tôi đã thêm đoạn mã sau trong phương pháp onCreate() trong MyApplication lớp:

@Override 
public void onCreate() { 
    AirshipConfigOptions options = new AirshipConfigOptions(); 
    options.developmentAppKey = "sdgsdgsdhsdh"; 
    options.developmentAppSecret = "sdhsdhsdhsdhsh"; 
    options.productionAppKey = "Your Production App Key"; 
    options.productionAppSecret = "Your Production App Secret"; 
    options.inProduction = false; 

    options.gcmSender = "11111111"; 

    UAirship.takeOff(this, options); 

    NotificationActionButton hiButtonAction = new NotificationActionButton.Builder("btnSave") 
      .setLabel(R.string.save) 
      .setPerformsInForeground(true) 
      .build(); 

    // Define the group 
    NotificationActionButtonGroup buttonGroup = new NotificationActionButtonGroup.Builder() 
      .addNotificationActionButton(hiButtonAction) 
      .build(); 

    // Add the custom group 
    UAirship.shared().getPushManager().addNotificationActionButtonGroup("save", buttonGroup); 

    UAirship.shared().getPushManager().setUserNotificationsEnabled(true); 

    UAirship.shared().getPushManager().setPushEnabled(true); 
} 

Sau đó tôi đã cố gắng thử nghiệm push từ tài khoản Urban Airship của tôi:

EDIT:

Tôi đã sử dụng API Airship đô thị v3. Theo official documentation Tôi đã gửi push với json:

{ 
    "audience": { 
    "named_user": "2971" 
    }, 
    "device_types":["android"], 
    "notification": { 
    "android": { 
     "alert": "Hello", 
     "extra": { 
     "EEID": "2971", 
     "DATE": "20150601" 
     }, 
     "interactive": { 
     "type": "save" 
     } 
    } 
    } 
} 

Nhưng tôi đã nhận được tổng push thông báo với "Hello" text và không có bất kỳ nút.

Điều gì có thể gây ra sự cố và cách mở một số hoạt động bằng cách nhấp vào nút trong thông báo?

Xin cảm ơn trước.

+0

Nếu tôi nhớ chính xác, nhà soạn nhạc "thử nghiệm đẩy" không có khả năng gửi thông báo tương tác. Bạn sẽ cần phải gửi thông báo thông qua các nhà soạn nhạc đẩy bình thường. Hoặc chỉ cần gửi thông qua API như được ghi ở đây: http://docs.urbanairship.com/api/ua.html#interactive-notifications – dperconti

+0

Cuối cùng tôi đã tìm thấy câu trả lời. Tôi không nhìn thấy nút này "Lưu" trong thông báo của tôi vì tôi có điện thoại kết nối với PC qua USB. http://stackoverflow.com/a/18477621/1225669 – anivaler

+0

Chà, vấn đề thú vị. Nó có hiển thị nếu bạn cố mở rộng thông báo theo cách thủ công không? – ralepinski

Trả lời

0

Khóa "danh mục" không chính xác trên Android. Nó thực sự đang tìm kiếm "com.urbanairship.interactive_type". Tuy nhiên, bạn nên sử dụng trình soạn thảo chính hoặc API đẩy trực tiếp.

curl -v -X POST -u <APP_KEY>:<MASTER_SECRET> -H "Content-type: application/json" -H "Accept: application/vnd.urbanairship+json; version=3;" --data '{ 
    "audience":"ALL", 
    "device_types":["android"], 
    "notification": { 
     "android": { 
      "alert": "Hello", 
      "interactive": { 
       "type": "save" 
      } 
     } 
    } 
}' https://go.urbanairship.com/api/push/ 

Nhưng với các ứng dụng thông tin của bạn cho <APP_KEY>:<MASTER_SECRET>

Xem http://docs.urbanairship.com/api/ua.html#interactive-api để biết thêm chi tiết.

+0

Ok. Tôi sẽ lấy lại cho bạn. Một câu hỏi nữa. Tôi có nên tạo NotificationFactory tùy chỉnh để hiển thị nút "Lưu" trong thông báo không? – anivaler

+0

Không. Nó không hiệu quả với tôi. Tôi đã nhận được thông báo chung mà không cần bất kỳ nút nào. – anivaler

+0

Nếu bạn đang sử dụng một nhà máy thông báo tùy chỉnh thì bạn phải gọi 'builder.extend (createNotificationActionsExtender (message, notificationId));' để nhận thông báo hoạt động. – ralepinski

Các vấn đề liên quan