Sono un enorme noob alla programmazione Android, quindi mi dispiace se questo è un compito semplice. Ho seguito praticamente il tutorial di notifica push di Vogella per le notifiche push (http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html). Ho letto alcune altre domande sull'overflow dello stack, ma sono un po 'confuso su come aprire un intent una volta ricevuta la notifica.Attività di apertura dopo aver fatto clic su notifica push android
Ad esempio, se volessi che la notifica mi portasse su un sito Web, come funzionerebbe? Dovrebbe andare sotto il mio MessageReceivedActivity o un altro progetto/classe tutti insieme?
Grazie
Ecco il codice che ho per il mio 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);
}
}
Quando faccio questo, dopo aver fatto clic sulla mia notifica push, vedo solo il messaggio "Nuovo messaggio ricevuto". Forse qualcosa deve dire al PendingIntent di aprire l'intento? – Kevin
Nevermind, capito attraverso il tuo codice. Dovevo solo cambiare 1 piccola cosa. Grazie! – Kevin