2012-02-20 94 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); 
相关问题