Ho un'applicazione che è fondamentalmente una visualizzazione Web e notifiche GCM. Voglio raggiungere la seguente cosa: se l'utente è nell'app e riceve una notifica, quando fa clic sulla notifica voglio che la webview carichi l'url fornito nella notifica.Invia trasmissione per notifica click
Sto provando a farlo utilizzando il ricevitore di trasmissione ma non funziona.
mi iscrivo in modo dinamico il ricevitore nella MainActivity:
private void registerNotificationReceiver() {
final IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_LOAD_URL_FROM_NOTIFICATION);
Log.i(TAG, "registerNotificationReceiver()");
this.receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "notification received");
}
};
super.registerReceiver(this.receiver, filter);
}
E nel GCM Listener sto usando PendingIntent.getBroadast():
final Intent broadcastIntent = new Intent(MainActivity.ACTION_LOAD_URL_FROM_NOTIFICATION);
PendingIntent intent = PendingIntent.getBroadcast(getApplicationContext(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.setContentIntent(intent);
notification = notificationBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, notification);
non capisco il motivo per cui in OnReceive la classe MainActivity non viene chiamata. Il messaggio "notifica ricevuta" non viene visualizzato. Potete aiutarmi? Grazie :)
Sì, ora funziona quando il ricevitore è definita nel manifesto. Grazie :) Per raggiungere il mio obiettivo, avevo bisogno di utilizzare un altro ricevitore nel MainActivity, dove carico l'url. La trasmissione ad esso viene inviata dal primo ricevitore (quello che ho definito nel manifest). Funziona ora, ma non mi piace questo approccio. Mi sembra una cattiva pratica ... – definera
è la pratica * obbligatoria * ... Dio dice Google così ... – eduyayo