【问题标题】:Android, Urban AirShip - change the messageAndroid、Urban AirShip - 改变信息
【发布时间】:2012-02-20 10:56:02
【问题描述】:

如何将Android中的通知消息更改为本地化? 我只想更改从 Urban AirShip 收到的消息,然后它才会显示在通知栏上?

【问题讨论】:

  • 你想修改来自服务器的消息吗???
  • 是的,我只需要在通知方法显示之前更改消息。

标签: android notifications urbanairship.com


【解决方案1】:

您可以使用此方法:PushManager.shared().setNotificationBuilder(null); 并使用 SDK 的 android 通知发送您自己的通知

【讨论】:

  • 谢谢,我正在寻找一种禁用默认通知的方法
【解决方案2】:

是的,一旦您收到来自 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));


        }

            }
}

【讨论】:

  • 好的,如果我想以其他方式处理通知?用我的方式反应,不要使用Urban AirShip的默认系统?
  • 看到你可以创建自己的自定义布局,图标图像显示在通知栏上,请从 Urban airship 资源下载 sdk 示例代码,你可以看到一个名为 notification.xml 的文件可以使用如通知栏所示....您还想要什么...???
  • 我需要本地化消息,所以在它出现在通知栏之前我需要更改它。 Urban AirShip 我只想用来触发事件。
  • 我已经告诉过你,你不能在通知中显示修改后的消息,它将被自动处理。
  • 那么如何获取通知,但不显示在通知上?
【解决方案3】:

我找到了解决方案,它有点脏,但我知道我需要使用它。 在收到 Urban AirShip 的通知后,我取消所有并发送我自己的更改消息。

【讨论】:

    【解决方案4】:

    我阅读了答案并想出了一个综合解决方案。

    1. 您想禁用 UrbanAirship 的默认通知处理程序。如果您这样做,它根本不会生成并向您显示通知。 PushManager.shared().setNotificationBuilder(null);(使用 David T 的建议)

    2. 您想构建自己的通知。这可以在您的IntentReceiver 中完成。 This 链接可以解决问题。

    希望这对其他人有所帮助。

    【讨论】:

      【解决方案5】:

      请使用该代码禁用 Urban Airship 的通知,覆盖 BasicPushNotificationBuilder:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-11
        • 2012-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多