Открытие активности после нажатия push-уведомления android

Я большой новичок в программировании для Android, так что извините, если это простая задача. Я в значительной степени следовал руководству по push-уведомлениям Vogella для push-уведомлений (http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html). Я прочитал некоторые другие вопросы о переполнении стека, но я немного смущен тем, как открыть намерение после получения уведомления.

Например, если бы я просто хотел, чтобы уведомление привело меня на веб-сайт, как бы это работало? Должен ли он идти под моей MessageReceivedActivity или другим проектом/классом вместе?

Спасибо

Вот код, который у меня есть для моего C2DMMessageReceiver

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Log.w("C2DM", "Message Receiver called");
    if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
        Log.w("C2DM", "Received message");
        final String payload = intent.getStringExtra("payload");
        Log.d("C2DM", "dmControl: payload = " + payload);
        // TODO Send this to my application server to get the real data
        // Lets make something visible to show that we received the message
        createNotification(context, payload);

    }
}

public void createNotification(Context context, String payload) {
    NotificationManager notificationManager = (NotificationManager) context
           .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.ic_launcher,
            "Message received", System.currentTimeMillis());
    // Hide the notification after its selected
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    //adding LED lights to notification
    notification.defaults |= Notification.DEFAULT_LIGHTS;

    Intent intent = new Intent(context, MessageReceivedActivity.class);
    intent.putExtra("payload", payload);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
            intent, 0);
    notification.setLatestEventInfo(context, "Message",
            "New message received", pendingIntent);
    notificationManager.notify(0, notification);

}

}

5
задан Kevin 25 April 2012 в 05:00
поделиться