Documentos de Académico
Documentos de Profesional
Documentos de Cultura
WW
WW
FirebaseMessaging.getInstance().subscribeToTopic("enviarAtodos").addOnCompleteListe
ner(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(MainActivity.this,"Subscrito a enviar a
todos",Toast.LENGTH_SHORT).show();
}
});
especifico.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {llamarespecifico();}
});
atopico.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
llamaratopico();
}
});
}//fin del onCreate
try {
//Configuración del token
json.put("to","/topics/"+"enviarAtodos");//A todos los que se
encuentren en el tópico subscritos les llegará el mensaje
JSONObject notificacion = new JSONObject();
//declaramos valores a recibir
notificacion.put("titulo","soy un titulo");
notificacion.put("detalle","soy un detalle");
json.put("data", notificacion);
//declaramos la URL de FireBase
String URL = "https://fcm.googleapis.com/fcm/send";
JsonObjectRequest request = new
JsonObjectRequest(Request.Method.POST,URL,json,null,null){
//Generamos un map
@Override
public Map<String, String> getHeaders() {
Map<String,String> header = new HashMap<>();
header.put("content-type","aplication/json");
header.put("authorization","key=AAAAgP9gN88:APA91bHmddC2LoKlLmWaRKqrsSGSsWchbgIGDew
Lfb_J7PQ-
t89BR96hykzGQSuVMFvnmeyHoh0OMbtSvyBPuM43QheFuEfMc3lRqnyE1Mxiz6e8RgFMzeRz7chgH-
neWgOmR6IdmZE3");
return header;
}
};
myrequest.add(request);
}catch (JSONException e){
e.printStackTrace();
}
}