0

I want send notification from server and panel firebase,i want when send push notification from panel firebase and click notification open url and send push from server open app but when send push from panel firebase app is force close,how to can solved this problem?this is my code

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);


    String title = remoteMessage.getNotification().getTitle();
    String message = remoteMessage.getNotification().getBody();


    String url = remoteMessage.getData().get("url");
    String message1 = remoteMessage.getData().get("message");
    String title1 = remoteMessage.getData().get("title");
    if (!title.equals("null") && !title.isEmpty()) {

        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);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
        notificationBuilder.setContentTitle(title);
        notificationBuilder.setContentText(message);
        notificationBuilder.setSmallIcon(R.drawable.khatemsalavet);
        notificationBuilder.setAutoCancel(true);
        notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        notificationBuilder.setContentIntent(pendingIntent);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, notificationBuilder.build());

    } else {
        Intent intent1 = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.parse(url);
        intent1.setData(uri);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent1, PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
        notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        notificationBuilder.setContentTitle(title1);
        notificationBuilder.setContentText(message1);
        notificationBuilder.setAutoCancel(true);
        notificationBuilder.setSmallIcon(R.drawable.khatemsalavet);
        notificationBuilder.setContentIntent(pendingIntent);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, notificationBuilder.build());


    }

}

error

E/AndroidRuntime: FATAL EXCEPTION: pool-3-thread-1 java.lang.NullPointerException at com.example.kaveh.khasalavatonline.FcmMessagingService.onMessageReceived(FcmMessagingService.java:32) at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(Unknown Source) at com.google.firebase.iid.zzc.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:841)

Java_User
  • 1,303
  • 3
  • 27
  • 38
jad
  • 23
  • 3

0 Answers0