Search in sources :

Example 1 with DeviceUploadGcmToken

use of de.tum.in.tumcampusapp.api.app.model.DeviceUploadGcmToken in project TumCampusApp by TCA-Team.

the class GcmIdentificationService method sendTokenToBackend.

/**
 * Sends the registration ID to your server over HTTP, so it can use GCM/HTTP
 * or CCS to send messages to your app. Not needed for this demo since the
 * device sends upstream messages to a server that echoes back the message
 * using the 'from' address in the message.
 */
private void sendTokenToBackend(String token) {
    // Check if all parameters are present
    if (token == null || token.isEmpty()) {
        Utils.logv("Parameter missing for sending reg id");
        return;
    }
    // Try to create the message
    DeviceUploadGcmToken dgcm;
    try {
        dgcm = DeviceUploadGcmToken.Companion.getDeviceUploadGcmToken(mContext, token);
    } catch (NoPrivateKey noPrivateKey) {
        return;
    }
    TUMCabeClient.getInstance(mContext).deviceUploadGcmToken(dgcm, new Callback<TUMCabeStatus>() {

        @Override
        public void onResponse(@NonNull Call<TUMCabeStatus> call, @NonNull Response<TUMCabeStatus> response) {
            TUMCabeStatus s = response.body();
            if (response.isSuccessful() && s != null) {
                Utils.logv("Success uploading GCM registration id: " + s.getStatus());
                // Store in shared preferences the information that the GCM registration id
                // was sent to the TCA server successfully
                Utils.setSetting(mContext, Const.GCM_REG_ID_SENT_TO_SERVER, true);
            } else {
                Utils.logv("Uploading GCM registration failed...");
            }
        }

        @Override
        public void onFailure(@NonNull Call<TUMCabeStatus> call, @NonNull Throwable t) {
            Utils.log(t, "Failure uploading GCM registration id");
            Utils.setSetting(mContext, Const.GCM_REG_ID_SENT_TO_SERVER, false);
        }
    });
}
Also used : DeviceUploadGcmToken(de.tum.in.tumcampusapp.api.app.model.DeviceUploadGcmToken) NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey) TUMCabeStatus(de.tum.in.tumcampusapp.api.app.model.TUMCabeStatus)

Aggregations

NoPrivateKey (de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey)1 DeviceUploadGcmToken (de.tum.in.tumcampusapp.api.app.model.DeviceUploadGcmToken)1 TUMCabeStatus (de.tum.in.tumcampusapp.api.app.model.TUMCabeStatus)1