Android - Notificaciones Push Firebase

 
Vista:
Imágen de perfil de Luis David
Val: 6
Ha aumentado su posición en 25 puestos en Android (en relación al último mes)
Gráfica de Android

Notificaciones Push Firebase

Publicado por Luis David (4 intervenciones) el 28/08/2016 00:22:53
Buenas tardes,

Soy nuevo en android studio, estoy desarrollando una app que utiliza Firebase para recibir notificaciones push, esa notificación me trae un id, al darle click a ese id me lleva a un activity en especifico.

Cuando la app esta en primer plano funciona perfecto, El problema es cuando la app esta en segundo plano, llega la notificación y se hace click en la notificacion, no me lleva al activity deseado sino al activity principal el de loggin

Este es mi código para crear las notificaciones
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
private void sendNotification(String body, RemoteMessage remoteMessage) {
        String __id="";
        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.iconom)
                .setContentTitle("Message")
                .setContentText(body)
                .setDefaults(Notification.DEFAULT_ALL)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setAutoCancel(true)
                .setSound(defaultSoundUri);
 
 
        Map<String, String> data = remoteMessage.getData();
        if(remoteMessage.getData().size() > 0){
            __id=data.get("id");
 
        }
        Intent intent = new Intent(this, Detalle.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if(__id!=""){
            intent.putExtra("ID",__id);
        }
 
 
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(Detalle.class);
        stackBuilder.addNextIntent(intent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        notificationBuilder.setContentIntent(resultPendingIntent);
        notificationBuilder.setAutoCancel(true);
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, notificationBuilder.build());
 
 
 
    }

este codigo esta dentro de la clase


1
public class MyFirebaseMessagingService extends FirebaseMessagingService{}


y en el Manifest esta asi

1
2
3
4
5
<service android:name=".MyFirebaseMessagingService">
        <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
</service>


Como podría hacer para solucionar este problema

De antemano agradezco su ayuda
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Notificaciones Push Firebase

Publicado por juancarlospatoja (1 intervención) el 30/10/2016 00:48:23
Me paso lo mismo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Luis David
Val: 6
Ha aumentado su posición en 25 puestos en Android (en relación al último mes)
Gráfica de Android

Notificaciones Push Firebase

Publicado por Luis David (4 intervenciones) el 30/10/2016 03:09:12
Juan en problema no esta en el código android, esta en como te envían la notificación, para que no ocurra este problema tienen que enviarte la notificación desde PHP u otro lenguaje de back-end y el array no se debe llamar notificación sino data.

aca te dejo un ejemplo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function sendGCM($message, $id) {
 
 
    $url = 'https://fcm.googleapis.com/fcm/send';
 
    $fields = array (
            'registration_ids' => array (
                    $id
            ),
            'data' => array (
                    "message" => $message
            )
    );
    $fields = json_encode ( $fields );
 
    $headers = array (
            'Authorization: key=' . "YOUR_KEY_HERE",
            'Content-Type: application/json'
    );
 
    $ch = curl_init ();
    curl_setopt ( $ch, CURLOPT_URL, $url );
    curl_setopt ( $ch, CURLOPT_POST, true );
    curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
 
    $result = curl_exec ( $ch );
    echo $result;
    curl_close ( $ch );
}
 
?>



otra cosa importante es hacer "finish" en el onpause de los activity.

aca un ejemplo

1
2
3
4
protected void onPause(){
        super.onPause();
        finish();
    }

espero que esto solucione tu problema
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar