BluestackAPK模拟器收到通知,但在智能手机FirebaseAndroidStudio上没有生成通知。
创始人
2024-12-23 02:30:20
0
  1. 确保已正确设置Firebase Cloud Messaging和相关依赖库。

  2. 在您的Android应用程序中添加FirebaseMessagingService类。

  3. 在FirebaseMessagingService类中,覆盖onMessageReceived方法并对通知进行处理。以下是示例代码:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    private static final String TAG = "MyFirebaseMsgService";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // Handle data payload of FCM messages.
        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());
            // Handle data message
            // ...
        }

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

    // ...
}
  1. 在sendNotification方法中,使用NotificationCompat.Builder创建通知。

以下是示例代码:

private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    String channelId = getString(R.string.default_notification_channel_id);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this, channelId)
                    .setSmallIcon(R.drawable.ic_notification)
                    .setContentTitle(getString(R.string.app_name))
                    .setContentText(messageBody)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    // Since android Oreo notification channel is needed.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O

相关内容

热门资讯

wepoke辅助插件!wepo... wepoke辅助插件!wepoke存在外挂(辅助挂)原来是真的有挂(详细辅助软件教程);大神普及一款...
德州ai人工智能!微扑克系统发... 德州ai人工智能!微扑克系统发牌(透视辅助)确实是真的有挂(详细辅助黑科技教程);原来确实真的有挂(...
智星德州菠萝外挂!微扑克wpk... 智星德州菠萝外挂!微扑克wpk辅助软件(透视辅助)的确真的有挂(详细辅助透视脚本教程);大神普及一款...
aapoker猫腻!aapok... aapoker猫腻!aapoker俱乐部后天可以操作(黑科技)竟然真的有挂(详细辅助软件教程);《W...
微扑克辅助软件!wpk数据抓包... 微扑克辅助软件!wpk数据抓包(黑科技辅助挂)的确是真的有挂(详细辅助脚本教程);亲,其实确实真的有...
wpk有辅助挂!wepoke是... wpk有辅助挂!wepoke是有软件(黑科技)原来真的有挂(详细透视脚本教程);1.wepoke a...
wpk ai辅助!德扑之星有规... wpk ai辅助!德扑之星有规律(透视辅助)竟然真的有挂(详细辅助透视脚本教程)准备好在 ia的高塔...
wpk提高胜率!众合推扑克辅助... wpk提高胜率!众合推扑克辅助工具(透视)的确真的有挂(详细辅助挂教程);最新版本免费下载安装哦,具...
微扑克ai辅助!wepoke软... 相信很多朋友都在电脑上玩过wepoke吧,但是很多朋友都在抱怨用电脑玩起来不方便。为此小编给大家带来...
德州免费辅助神器app!pok... 1、德州免费辅助神器app!pokerx机器人(软件透明该)竟然真的有挂(详细代打辅助教程);详细教...