当前位置: 首页>>代码示例>>Java>>正文


Java RemoteMessage.getNotification方法代码示例

本文整理汇总了Java中com.google.firebase.messaging.RemoteMessage.getNotification方法的典型用法代码示例。如果您正苦于以下问题:Java RemoteMessage.getNotification方法的具体用法?Java RemoteMessage.getNotification怎么用?Java RemoteMessage.getNotification使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.firebase.messaging.RemoteMessage的用法示例。


在下文中一共展示了RemoteMessage.getNotification方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
	Utils.d("Message From: " + remoteMessage.getFrom());
	Utils.d("Message From: " + remoteMessage.toString());

	// Check if message contains a data payload.
	if (remoteMessage.getData().size() > 0) {
		Map<String, String> data = remoteMessage.getData();

		Utils.d("Message data payload: " + data.toString());

		KeyValueStorage.set_context(this);
		handleData(data);
	}

	// Check if message contains a notification payload.
	if (remoteMessage.getNotification() != null) {
		Utils.d(
		"Notification Body: " + remoteMessage.getNotification().getBody());

		sendNotification(remoteMessage.getNotification().getBody(), this);
	}
}
 
开发者ID:FrogSquare,项目名称:GodotFireBase,代码行数:24,代码来源:MessagingService.java

示例2: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    String notificationTitle = null, notificationBody = null;

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
        notificationTitle = remoteMessage.getNotification().getTitle();
        notificationBody = remoteMessage.getNotification().getBody();
    }

    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
    sendNotification(notificationTitle, notificationBody);
}
 
开发者ID:SinanYilmaz9,项目名称:CloudFunctionsExample,代码行数:17,代码来源:MyFirebaseMessagingService.java

示例3: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // ...

    // TODO(developer): Handle FCM messages here.
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());
    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
}
 
开发者ID:sivaraj-dev,项目名称:firebase-fcm-sample,代码行数:22,代码来源:MyFirebaseMessagingService.java

示例4: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    if (remoteMessage.getData().size() > 0) {
        // procesa los datos extra de la notificación
    }

    if (remoteMessage.getNotification() != null) {
        String title = remoteMessage.getNotification().getTitle();
        String message = remoteMessage.getNotification().getBody();
        String clickAction = remoteMessage.getNotification().getClickAction();


        Log.d(TAG, "Title: " + title);
        Log.d(TAG, "Message: " + message);
        Log.d(TAG, "clickAction: " + clickAction);

        sendNotification(title, message, clickAction);
    }

}
 
开发者ID:gothalo,项目名称:Android-2017,代码行数:22,代码来源:FirebaseMessangingService.java

示例5: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // ...

    // TODO(developer): Handle FCM messages here.
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());
        Map<String, String> data = remoteMessage.getData();

        sendNotification(data.get("message"),data.get("title"));

    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.

}
 
开发者ID:othreecodes,项目名称:WaJeun,代码行数:27,代码来源:PushService.java

示例6: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    //Log.e(TAG, "From: " + remoteMessage.getFrom());

    if (remoteMessage == null)
        return;

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        //Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
        handleNotification(remoteMessage.getNotification().getBody());
    }

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        //Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());

        try {
            JSONObject json = new JSONObject(remoteMessage.getData().toString());
            handleDataMessage(json);
        } catch (Exception e) {
            //Log.e(TAG, "Exception: " + e.getMessage());
        }
    }
}
 
开发者ID:safaricom,项目名称:LNMOnlineAndroidSample,代码行数:26,代码来源:MyFirebaseMessagingService.java

示例7: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());

    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
        sendNotification(remoteMessage.getNotification().getBody());
    }
}
 
开发者ID:micromasterandroid,项目名称:androidadvanced,代码行数:18,代码来源:MyFirebaseMessagingService.java

示例8: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (!GameDatabase.getInstance().credentialsStored(this)) {
        //We are not logged in, do nothing.
        return;
    }

    String json = remoteMessage.getData().get("announcement");
    if (json != null) {
        Announcement ann = JsonUtils.jsonToObject(json, Announcement.class);
        if (ann != null) {
            Log.d(TAG, "Saved announcement to database: " + ann.remoteId);
            StorageDatabase.getInstance().updateAnnouncement(ann, null);
        }
    }

    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Got notification");
        sendNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
    }
    else {
        Log.d(TAG, "No notification payload");
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-android,代码行数:25,代码来源:RiistaFirebaseMessagingService.java

示例9: showNotification

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
private void showNotification(RemoteMessage remoteMessage) {
    if (remoteMessage != null && remoteMessage.getNotification() != null) {
        String title = getString(R.string.txt_app_name);
        String message = "";

        Intent intent = new Intent(this, LaunchActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        if (remoteMessage.getNotification().getTitle() != null) {
            title = remoteMessage.getNotification().getTitle();
        }

        if (remoteMessage.getNotification().getBody() != null) {
            message = remoteMessage.getNotification().getBody();
        }


        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setContentTitle(title)
                .setContentText(message)
                .setSmallIcon(R.drawable.notification_icon)
                .setAutoCancel(true)
                .setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification))
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(DCSharedPreferences.getNotificationId(), notificationBuilder.build());
    }
}
 
开发者ID:Dentacoin,项目名称:aftercare-app-android,代码行数:31,代码来源:DCFirebaseMessagingService.java

示例10: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
/**
 * Called when message is received.
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // [START_EXCLUDE]
    // There are two types of messages data messages and notification messages. Data messages are handled
    // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
    // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
    // is in the foreground. When the app is in the background an automatically generated notification is displayed.
    // When the user taps on the notification they are returned to the app. Messages containing both notification
    // and data payloads are treated as notification messages. The Firebase console always sends notification
    // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
    // [END_EXCLUDE]

    // TODO(developer): Handle FCM messages here.
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());
    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
}
 
开发者ID:rahul051296,项目名称:quake-alert-android-app,代码行数:36,代码来源:MyFirebaseMessagingService.java

示例11: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.i(TAG, "DESDE: " + remoteMessage.getFrom());

    if(remoteMessage.getData().size() > 0){
        Log.i(TAG, "Data de mensaje: " + remoteMessage.getData());
    }

    if(remoteMessage.getNotification() != null){
        Log.i(TAG, "Notificacion.body: " + remoteMessage.getNotification().getBody());
        sendNotification(remoteMessage.getNotification().getBody());
    }
}
 
开发者ID:AmauryOrtega,项目名称:Sem-Update,代码行数:14,代码来源:MyFirebaseMessagingService.java

示例12: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
/**
 * Called when a message is received.
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    String title;
    String text;
    String id;
    Map<String, String> data = remoteMessage.getData();
    RemoteMessage.Notification notification = remoteMessage.getNotification();

    if (notification != null) {
        title = notification.getTitle();
        text = notification.getBody();
        id = remoteMessage.getMessageId();
    } else {
        title = data.get("title");
        text = data.get("text");
        id = data.get("id");
    }

    if (TextUtils.isEmpty(id)) {
        Random rand = new Random();
        int n = rand.nextInt(50) + 1;
        id = Integer.toString(n);
    }

    Log.i(TAG, "From: " + remoteMessage.getFrom());
    Log.i(TAG, "Notification Message id: " + id);
    Log.i(TAG, "Notification Message Title: " + title);
    Log.i(TAG, "Notification Message Body/Text: " + text);

    if (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(title) || (!remoteMessage.getData().isEmpty())) {
        boolean showNotification = (Firebase.inBackground() || !MessagingComponent.hasNotificationsCallback())
                && (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(title));
        sendNotification(id, title, text, data, showNotification);
    }
}
 
开发者ID:jsayol,项目名称:cordova-plugin-firebase-sdk,代码行数:41,代码来源:MessagingService.java

示例13: mapToNotificationBuilder

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
/**
 * Map a FCM remote message into a System Notification Builder mimicking the default notification format and behavior applied when the app is in background
 *
 * @param remoteMessage FCM remote message
 * @return The notification builder configured with the notification information of the remote message
 * @throws IllegalArgumentException if the remote message does not contain notification information
 */
public NotificationCompat.Builder mapToNotificationBuilder(RemoteMessage remoteMessage) throws IllegalArgumentException {
    RemoteMessage.Notification fcmNotification = remoteMessage.getNotification();

    if (fcmNotification == null)
        throw new IllegalArgumentException(ErrorMessages.NO_NOTIFICATION_MSG);

    String body = parseBody(fcmNotification);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentTitle(parseTitle(fcmNotification))
            .setContentText(body)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(body))
            .setSmallIcon(parseIcon(fcmNotification))
            .setAutoCancel(true);

    Integer color;
    if ((color = parseColor(fcmNotification)) != null) {
        builder.setColor(color);
    }

    int soundFileResId;
    if (fcmNotification.getSound() != null &&
            !fcmNotification.getSound().equals("default") &&
            (soundFileResId = context.getResources().getIdentifier(fcmNotification.getSound(), "raw", context.getPackageName())) != 0) {

        builder.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + soundFileResId));

    } else if (fcmNotification.getSound() != null) {
        builder.setDefaults(Notification.DEFAULT_SOUND);
    }

    builder.setContentIntent(createNotificationPendingItent(remoteMessage));

    return builder;
}
 
开发者ID:franmontiel,项目名称:FcmNotificationHandler,代码行数:42,代码来源:RemoteMessageToNotificationMapper.java

示例14: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
/**
 * Called when message is received.
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // [START_EXCLUDE]
    // There are two types of messages data messages and notification messages. Data messages are handled
    // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
    // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
    // is in the foreground. When the app is in the background an automatically generated notification is displayed.
    // When the user taps on the notification they are returned to the app. Messages containing both notification
    // and data payloads are treated as notification messages. The Firebase console always sends notification
    // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
    // [END_EXCLUDE]

    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
        sendNotification(remoteMessage);
    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Logger.d("Message data payload: " + remoteMessage.getData());

        if (/* Check if data needs to be processed by long running job */ true) {
            // For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
            scheduleJob();
        } else {
            // Handle message within 10 seconds
            handleNow();
        }

    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Logger.d("Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
}
 
开发者ID:nyangate,项目名称:Crypto-Assistant,代码行数:43,代码来源:FbMessagingService.java

示例15: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
/**
 * Called when message is received.
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // [START_EXCLUDE]
    // There are two types of messages data messages and notification messages. Data messages are handled
    // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
    // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
    // is in the foreground. When the app is in the background an automatically generated notification is displayed.
    // When the user taps on the notification they are returned to the app. Messages containing both notification
    // and data payloads are treated as notification messages. The Firebase console always sends notification
    // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
    // [END_EXCLUDE]

    // TODO(developer): Handle FCM messages here.
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());
    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
    sendNotification(remoteMessage.getData().get("message"));
}
 
开发者ID:narenkukreja,项目名称:quire,代码行数:37,代码来源:MyFirebaseMessagingService.java


注:本文中的com.google.firebase.messaging.RemoteMessage.getNotification方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。