简体   繁体   English

'发送消息'Firebase云消息传递服务时出错

[英]'Error sending message' Firebase Cloud Messaging Service

I was using the Firebase Notification in my app. 我在我的应用中使用了Firebase通知。 Everything is setup but when i push the notification from the console, I get this error : 一切都设置但是当我从控制台推送通知时,我收到此错误:

截图

Here is my code : MyFirebaseInstanceIDService.class 这是我的代码:MyFirebaseInstanceIDService.class

package notes.ronak.com.pushnotificationfromstart;

import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

/**
 * Created by ronaksakhuja on 12/9/16.
 */
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
    private static final String TAG="MyFirebaseInsIDServicve";

    @Override
    public void onTokenRefresh() {
        //Get updated token
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG,"New Token : "+refreshedToken);
        sendRegistrationToServer(refreshedToken);


        //You can save the token into third party server to do anything you want
    }

    private void sendRegistrationToServer(String refreshedToken) {
    }
}

MyFirebaseMessagingService.class MyFirebaseMessagingService.class

package notes.ronak.com.pushnotificationfromstart;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

/**
 * Created by ronaksakhuja on 12/9/16.
 */
public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG="MyFirebaseMsgService";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

        Log.d(TAG,"FROM :"+remoteMessage.getFrom());

        //check if msg contains data

        if(remoteMessage.getData().size()>0){
            Log.d(TAG,"Message data : "+remoteMessage.getData());
        }

        //check if msg contains notification

        if(remoteMessage.getNotification()!=null){
            Log.d(TAG,"Message body : "+remoteMessage.getNotification().getBody());
            sendNotification(remoteMessage.getNotification().getBody());
        }

    }

    private void sendNotification(String body) {
        Intent intent = new Intent(this,MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
        Uri notiifcationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notification = new NotificationCompat.Builder(this).setContentTitle("Firebase Title").setContentText(body).setContentIntent(pendingIntent).setSound(notiifcationSound).setAutoCancel(true);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0,notification.build());
    }
}

MainActivity.class MainActivity.class

package notes.ronak.com.pushnotificationfromstart;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.firebase.iid.FirebaseInstanceId;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private static final String TAG="MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button showtoken= (Button) findViewById(R.id.button);
        showtoken.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        //Get the token
        String token = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG,"Token : "+token);
        Toast.makeText(MainActivity.this, "Token : "+token, Toast.LENGTH_SHORT).show();

    }
}

I have included the required services in the manifest. 我已在清单中包含所需的服务。

` `

Just Clear Your browser Cache. 只需清除您的浏览器缓存。

or 要么

Sign Out from you Firebase Console and again SignIn. 从Firebase控制台退出并再次登录。

or 要么

Change your Browser. 更改您的浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase Cloud消息传递:消息发送和接收之间的随机延迟? - Firebase Cloud messaging : random delay between sending and reception of message? 将JSON发送到Firebase Cloud Messaging - Sending JSON to Firebase Cloud Messaging MismatchSenderId错误Firebase云消息传递(FCM) - MismatchSenderId error Firebase Cloud Messaging (FCM) Android:Firebase 云消息传递不发送通知以构建 .apk - Android: Firebase Cloud Messaging not sending notification to build .apk 使用 firebase 云消息传递我如何了解哪条消息给我一个错误以及哪条消息被接受交付? - using firebase cloud messaging how can I understand which message give me an error and which message is accepted for delivery? 如何向FCM(Firebase云消息传递)令牌的特定用户发送消息? - How to send a message to a specific user of an FCM (Firebase Cloud Messaging) token? 如何修复 Google Cloud Messaging 注册错误:SERVICE_NOT_AVAILABLE? - How to fix Google Cloud Messaging Registration error: SERVICE_NOT_AVAILABLE? Firebase 云消息传递 - onMessageReceived 不起作用 - Firebase Cloud Messaging - onMessageReceived not working 使用Firebase云消息传递的通知 - Notification using Firebase cloud Messaging Firebase错误400发送HttpPost消息 - Firebase Error 400 Sending HttpPost message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM