2012-02-20 100 views
1

如何更改Android中的通知消息以進行本地化? 我只想更改從Urban AirShip獲取的消息,然後纔會顯示在通知欄上?Android,Urban AirShip - 更改消息

+0

你想修改從服務器傳來的消息??? – 2012-02-20 11:13:18

+0

是的,我只需要在通知方法顯示之前更改消息。 – goodm 2012-02-20 11:23:45

回答

0

檢查消息我找到了解決辦法,它的種類一葷一,但知道對不對,我需要用這個。 剛剛從Urban AirShip收到通知後,我取消了所有通知,並通過更改後的信息發送了我自己的通知。

0

是的,您可以在收到Urban AirShip的消息後修改該消息,以便在應用程序中內部使用,但無法在通知欄中顯示修改的消息。

您可以在IntentReceiver

public class IntentReceiver extends BroadcastReceiver { 

    private static final String logTag = "Hey"; 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.i(logTag, "Received intent: " + intent.toString()); 
     String action = intent.getAction(); 

     if (action.equals(PushManager.ACTION_PUSH_RECEIVED)) { 

       int id = intent.getIntExtra(PushManager.EXTRA_NOTIFICATION_ID, 0); 

      Log.v(logTag, "Received push notification. Alert: " + intent.getStringExtra(PushManager.EXTRA_ALERT) 
       + ". Payload: " + intent.getStringExtra(PushManager.EXTRA_STRING_EXTRA) + ". NotificationID="+id); 

       //can get your message here 

     } else if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) { 

      Log.v(logTag, "User clicked notification. Message: " + intent.getStringExtra(PushManager.EXTRA_ALERT)+ ".Payload:" + intent.getStringExtra("PushManager.EXTRA_STRING_EXTRA")); 


      Intent launch = new Intent(Intent.ACTION_MAIN); 

      UAirship.shared().getApplicationContext().startActivity(launch); 

     } else if (action.equals(PushManager.ACTION_REGISTRATION_FINISHED)) { 
      Log.i(logTag, "Registration complete. APID:" + intent.getStringExtra(PushManager.EXTRA_APID) 
        + ". Valid: " + intent.getBooleanExtra(PushManager.EXTRA_REGISTRATION_VALID, false)); 


     } 

      } 
} 
+0

好的,如果我想以其他方式處理通知?只需按照我的方式做出反應,不要使用Urban AirShip的默認系統? – goodm 2012-02-20 11:41:34

+0

看到你可以創建你自己的圖標圖像的自定義佈局顯示在通知欄上,請從Urban airship資源下載sdk示例代碼,你可以看到有一個名爲notification.xml的文件,可以用來顯示在通知欄中。 ..你想要的其他東西...? – 2012-02-20 11:46:34

+0

我需要對消息進行本地化,因此在它出現在通知欄上之前,我需要對其進行更改。 Urban AirShip我想只用於觸發事件。 – goodm 2012-02-20 11:53:45

7

您可以使用此方法:PushManager.shared().setNotificationBuilder(null);,並與Android通知從SDK

+0

謝謝,我正在尋找一種方法來禁用默認通知 – Climbatize 2012-04-10 12:13:42

0

我讀答案,並用組合式的解決方案上來發送自己的通知。

  1. 您想要禁用UrbanAirship的默認通知處理程序。如果你這樣做,它不會生成並向你顯示通知。 PushManager.shared().setNotificationBuilder(null);(使用David T的建議)

  2. 你想建立你自己的通知。這可以在您的IntentReceiver內完成。 This鏈接將做的伎倆。

希望這可以幫助別人。

0

請使用代碼來禁用城市飛艇的通知,覆蓋BasicPushNotificationBuilder:

BasicPushNotificationBuilder nb = new BasicPushNotificationBuilder() { 
    @Override 
    public Notification buildNotification(String alert, 
      Map<String, String> extras) { 
     return null; 
    } 
}; 
// Disable notifications 
PushManager.shared().setNotificationBuilder(nb); 
相關問題