2015-07-15 8 views
8

Urban Airship SDK'yı, cihazımda uygulamam için Android 4.2 (Jelly Bean) ile entegre ettim. Genel push bildirimleri aldım. Tamam. Ancak "Save" etiketli buton ile etkileşimli push bildirimi almak istiyorum. Android'de Urban Airship ile etkileşimli bildirimi nasıl alırsınız?

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

official documentation göre, ben MyApplication sınıfta onCreate() yönteminde şu kodu ekledikten

:

Benim build.gradle gelen bağımlılıkları Bundan sonra

@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); 
} 

Ben deneme itmek denedim Urban Airship hesabımdan:

EDIT:

Urban Airship API v3 kullandım. official documentation göre ben json ile itmek gönderdik:

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

Ama "Merhaba" metin ile ve herhangi düğmeleri olmadan genel itme bildirim aldık.

Sorun nedir ve bildirim sırasında düğmeyi tıklayarak bazı etkinlikleri nasıl açabilirsiniz?

Şimdiden teşekkürler.

+0

Doğru hatırlıyorsam, "test itme" besteci etkileşimli bildirimleri gönderme yeteneğine sahip değil. Bildirimi normal itici besteci aracılığıyla göndermeniz gerekir. Ya da sadece burada belgelenen API aracılığıyla gönderin: http://docs.urbanairship.com/api/ua.html#interactive-notifications – dperconti

+0

Sonunda cevabı buldum. Telefonumdan USB ile bağlandığım için bildirimde "Kaydet" butonunu görmedim. http://stackoverflow.com/a/18477621/1225669 – anivaler

+0

Vay, eğlenceli bir konu. Bildirimi el ile genişletmeye çalışırsanız görünür mu? – ralepinski

cevap

0

Anahtar "kategori" Android'de doğru değil. Aslında "com.urbanairship.interactive_type" için arıyorum. Ancak, ana besteci veya push API'yi doğrudan kullanmanız gerekir.

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/ 

Ama <APP_KEY>:<MASTER_SECRET>

için uygulamalar kimlik Daha fazla ayrıntı için http://docs.urbanairship.com/api/ua.html#interactive-api Bkz ile

.

+0

Tamam. Sana döneceğim. Bir soru daha. Bildirimde "Kaydet" düğmesini göstermek için özel NotificationFactory oluşturmalı mıyım? – anivaler

+0

Hayır. Benim için çalışmıyor. Düğme olmadan genel bildirim aldım. – anivaler

+0

Özel bir bildirim fabrikası kullanıyorsanız, çalışmak için bildirim almak üzere 'builder.extend (createNotificationActionsExtender (message, notificationId)); – ralepinski

İlgili konular