ارسال نشدن نوتیفیکیشن در foreground

پرسیده شده
فعالیت 1171 روز پیش
دیده شده 457 بار
0

با سلام و عرض خسته نباشید خدمت دوستان و استاد عزیز،

مشکل : نوتیفیکیشن در حالت foreground ارسال نمایش داده نمیشه (اما با دیباگینگ reach میشه).

مواردی که تست شده : هم روی دیوایس فیزیکی و هم روی Emulator تست کردم و باز هم نمایش داده نشد.

 

MyMessagingService Class

package ir.pmoslem.pushnotificationtutorial;

import android.app.Notification;
import android.app.NotificationManager;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

public class MyMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        if (remoteMessage.getNotification() == null)
            return;
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        Notification notification = new NotificationCompat.Builder(this, "myapp")
                .setContentTitle(remoteMessage.getNotification().getTitle())
                .setContentText(remoteMessage.getNotification().getBody())
                .setSmallIcon(android.R.drawable.stat_notify_chat)
                .build();
        notificationManager.notify(1001, notification);
    }
}

App Class

package ir.pmoslem.pushnotificationtutorial;

import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            NotificationChannel notificationChannel = new NotificationChannel("myapp", "Default Notification Channel", NotificationManager.IMPORTANCE_HIGH);
            notificationChannel.setDescription("This is notification channel");
            if (notificationManager != null)
                notificationManager.createNotificationChannel(notificationChannel);
        }
    }
}
فایل پیوست

پارسا مسلم
پارسا مسلم

28 بهمن 99

0
حذف شده

سلام وقت بخیر پارسا جان

 

سرویستون رو در منیفست تعریف کردید؟

و همینطور کلاس App رو به منیفست برنامه معرفی کردید؟

فایل پیوست

پوریا شفیعی

توسط

پوریا شفیعی

28 بهمن 99

حذف شده
سلام پوریا عزیز، بله سرویس رو داخل منیفست تعریف کرده بودم ولی کلاس App رو داخل منیفست تعریف نکرده بودم؛ اما الان این مورد رو هم تست کردم و کلاس App رو نیز معرفی کردم اما همچنان در حالت Foreground نوتیفیکیشنی رو نمایش نمیده.
پارسا مسلم

28 بهمن 99

حذف شده
api که استفاده میکنید چی هست؟
پوریا شفیعی

29 بهمن 99

حذف شده
API؟ از API ای داخل اپلیکیشن استفاده نمیکنم.
پارسا مسلم

29 بهمن 99

حذف شده
منظورم به عنوان مثال Android 11 (API level 30) یا مثلا از کدوم ورژن اندروید برای تست اپلیکیشن استفاده میکنین
پوریا شفیعی

29 بهمن 99

حذف شده
آهان متوجه شدم؛ از API 30 استفاده می کنم.
پارسا مسلم

29 بهمن 99