gpt4 book ai didi

java - “发送消息时出错”Firebase 云消息服务

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:42:18 24 4
gpt4 key购买 nike

我在我的应用中使用了 Firebase 通知。一切都已设置,但是当我从控制台推送通知时,出现此错误:

Screenshot

这是我的代码: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

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

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();

}
}

我已在 list 中包含所需的服务。

`

最佳答案

只需清除您的浏览器缓存。

从您的 Firebase 控制台退出并重新登录。

更改您的浏览器。

关于java - “发送消息时出错”Firebase 云消息服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39447410/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com