【问题标题】:Urban airship push notifications城市飞艇推送通知
【发布时间】:2015-03-10 04:52:01
【问题描述】:

我想从我从城市飞艇发送的额外键值中获取值。请帮助如何获得这些值。我能够收到推送通知。但我不知道如何从有效载荷中获取数据。

public class IntentReceiver extends BaseIntentReceiver {

    private static final String TAG = "IntentReceiver";
    private String video_id ="123456";

    @Override
    protected void onChannelRegistrationSucceeded(Context context, String channelId) {
        Log.i(TAG, "Channel registration updated. Channel Id:" + channelId + ".");

        // Broadcast that the channel updated. Used to refresh the channel ID on the main activity.
        LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(MainActivity.ACTION_UPDATE_CHANNEL));
    }

    @Override
    protected void onChannelRegistrationFailed(Context context) {
        Log.i(TAG, "Channel registration failed.");
    }
    @Override
    protected void onPushReceived(Context context, PushMessage message, int notificationId) {
        Log.i(TAG, "Received push notification. Alert: " + message.getTitle() + ". Notification ID: " + notificationId);


    @Override
    protected void onBackgroundPushReceived(Context context, PushMessage message) {
        Log.i(TAG, "Received background push message: " + message);
    }

    @Override
    protected boolean onNotificationOpened(Context context, PushMessage message, int notificationId) {
        Intent launch = new Intent(Intent.ACTION_MAIN);
        launch.setClass(UAirship.shared().getApplicationContext(),
                MainActivity.class);
        launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        launch.putExtra("NotificationMessage", "rich push notification recieved");
        context.startActivity(launch);
        /*//pending intent
        Intent notificationIntent = new Intent(context, MainActivity.class);
        Notification notification = new Notification();
        notificationIntent.putExtra("NotificationMessage", "rich push notification recieved");
        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingNotificationIntent = PendingIntent.getActivity(context,0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.setLatestEventInfo(context, "", "", pendingNotificationIntent);*/
        return false;
    }

    @Override
    protected boolean onNotificationActionOpened(Context context, PushMessage message, int notificationId, String buttonId, boolean isForeground) {
        Log.i(TAG, "User clicked notification button. Button ID: " + buttonId + " Alert: " + message.getAlert());
        return false;
    }


    @Override
    protected void onNotificationDismissed(Context context, PushMessage message, int notificationId) {
        Log.i(TAG, "Notification dismissed. Alert: " + message.getAlert() + ". Notification ID: " + notificationId);
    }
}

【问题讨论】:

    标签: java urbanairship.com


    【解决方案1】:

    要获取额外数据,请在消息上使用 getPushBundle。所以如果我有一个叫做“动作”的东西,那就是这个。

        Bundle pushBundle = message.getPushBundle();
    
        String action = null;
        if (pushBundle != null) {
            action = pushBundle.get("action").toString();
        }
    

    【讨论】:

      【解决方案2】:

      正如@Koppo 所说,您可以从 PushMessage 中取出捆绑包 捆绑 pushBundle = message.getPushBundle();

      并迭代捆绑包并获取其中的所有附加功能。然后您可以决定为您的应用程序进一步处理哪一个 还有一篇关于这个迭代逻辑的文章。你也可以检查一下 https://stackoverflow.com/a/16782044/4781403

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多