Android, Urban AirShip - change the message

2019-08-15 16:33发布

How to change the notification message in Android to localised it? I just want to change the message what I get from Urban AirShip before it will be display on notification bar?

5条回答
戒情不戒烟
2楼-- · 2019-08-15 17:11

I found the solution, its kind a dirty one, but right know I need to use this. Just after get notification from Urban AirShip I cancel all and send my own with changed message.

查看更多
Root(大扎)
3楼-- · 2019-08-15 17:14

You can using this method: PushManager.shared().setNotificationBuilder(null); and send your own notification with android notification from the SDK

查看更多
干净又极端
4楼-- · 2019-08-15 17:15

I read the answers and came up with a combined solution.

  1. You want to disable UrbanAirship's default notification handler. If you do that, it won't generate and show you the notifications at all. PushManager.shared().setNotificationBuilder(null); (Using David T's suggestion)

  2. You want to build your own notification. This can be done inside your IntentReceiver. This link will do the trick.

Hope this helps others.

查看更多
趁早两清
5楼-- · 2019-08-15 17:21

Please using that code to disable Urban Airship's notifications, override BasicPushNotificationBuilder:

BasicPushNotificationBuilder nb = new BasicPushNotificationBuilder() {
    @Override
    public Notification buildNotification(String alert,
            Map<String, String> extras) {
        return null;
    }
};
// Disable notifications
PushManager.shared().setNotificationBuilder(nb);
查看更多
疯言疯语
6楼-- · 2019-08-15 17:34

Yes you can modify the message once you receive the message from Urban AirShip for your internal use in the app but can't show the modified message in the notification bar.

You can check the message in your 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));


        }

            }
}
查看更多
登录 后发表回答