6

I was using the Firebase Notification in my app. Everything is setup but when i push the notification from the console, I get this error :

Screenshot

Here is my code : 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();

    }
}

I have included the required services in the manifest.

`

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user3217999
  • 61
  • 2
  • 3

1 Answers1

0

Just Clear Your browser Cache.

or

Sign Out from you Firebase Console and again SignIn.

or

Change your Browser.

Sheharyar Ejaz
  • 2,808
  • 1
  • 14
  • 15