Android 使用改装的Firebase设备到设备的消息传递,如何获取消息id?

Android 使用改装的Firebase设备到设备的消息传递,如何获取消息id?,android,firebase,retrofit2,Android,Firebase,Retrofit2,我使用改型来发送设备到设备的消息,而不使用php脚本和curl命令,一切正常。我需要保存已发送的邮件ID。成功发送已发送邮件的邮件ID后如何获取。我的密码。 发送活动 public void onClick(View view) { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient.Bu

我使用改型来发送设备到设备的消息,而不使用php脚本和curl命令,一切正常。我需要保存已发送的邮件ID。成功发送已发送邮件的邮件ID后如何获取。我的密码。 发送活动

public void onClick(View view) {

HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);

OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(new Interceptor() {
    @Override
    public okhttp3.Response intercept(Chain chain) throws IOException {
        Request original = chain.request();

        // Request customization: add request headers
        Request.Builder requestBuilder = original.newBuilder()
                .header("Authorization", "key=legacy server key from FB console"); // <-- this is the important line
        Request request = requestBuilder.build();
        return chain.proceed(request);
    }
});

httpClient.addInterceptor(logging);
OkHttpClient client = httpClient.build();

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl("https://fcm.googleapis.com")//url of FCM message server
        .client(client)
        .addConverterFactory(GsonConverterFactory.create())//use for convert JSON file into object
        .build();

// prepare call in Retrofit 2.0
FirebaseAPI firebaseAPI = retrofit.create(FirebaseAPI.class);

//for messaging server
NotifyData notifydata = new NotifyData("Notification title","Notification body");

Call<Message> call2 = firebaseAPI.sendMessage(new Message("...... device token ....", notifydata));

call2.enqueue(new Callback<Message>() {
    @Override
    public void onResponse(Call<Message> call, Response<Message> response) {

        Log.d("Response ", "onResponse");
        t1.setText("Notification sent");

    }

    @Override
    public void onFailure(Call<Message> call, Throwable t) {
        Log.d("Response ", "onFailure");
        t1.setText("Notification failure");
    }
});
}

和FirebaseAPI

public interface FirebaseAPI {

@POST("/fcm/send")
Call<Message> sendMessage(@Body Message message);

}
公共接口FirebaseAPI{
@邮寄(“/fcm/send”)
调用sendMessage(@Body Message);
}

我已扩展了我的邮件POJO

public class Message {
String to;
NotifyData notification;
String message_id;

public Message(String to, NotifyData notification, String message_id) {
    this.to = to;
    this.notification = notification;
    this.message_id = message_id;
    }

public String getMessage_id() {

    return message_id;
    }

}
发送FCM消息后,Firebase获取消息\u id作为响应

Call<Message> call2 = firebaseAPI.sendMessage(new Message(to, notifydata, ""));
    call2.enqueue(new Callback<Message>() {
        @Override
        public void onResponse(Call<Message> call, Response<Message> response) {

            Log.d("Response ", "onResponse");
            //t1.setText("Notification sent");
            Message message = response.body();
            Log.d("message", message.getMessage_id());

        }

        @Override
        public void onFailure(Call<Message> call, Throwable t) {
            Log.d("Response ", "onFailure");
            //t1.setText("Notification failure");
        }
    });
call2=firebaseAPI.sendMessage(新消息(to,notifydata,”);
call2.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
Log.d(“响应”、“onResponse”);
//t1.setText(“已发送通知”);
Message=response.body();
Log.d(“message”,message.getMessage_id());
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
日志d(“响应”、“失败”);
//t1.setText(“通知失败”);
}
});
public class Message {
String to;
NotifyData notification;
String message_id;

public Message(String to, NotifyData notification, String message_id) {
    this.to = to;
    this.notification = notification;
    this.message_id = message_id;
    }

public String getMessage_id() {

    return message_id;
    }

}
Call<Message> call2 = firebaseAPI.sendMessage(new Message(to, notifydata, ""));
    call2.enqueue(new Callback<Message>() {
        @Override
        public void onResponse(Call<Message> call, Response<Message> response) {

            Log.d("Response ", "onResponse");
            //t1.setText("Notification sent");
            Message message = response.body();
            Log.d("message", message.getMessage_id());

        }

        @Override
        public void onFailure(Call<Message> call, Throwable t) {
            Log.d("Response ", "onFailure");
            //t1.setText("Notification failure");
        }
    });