ПОЧЕМУ ЛЮДИ НЕ ПОМОГАЮТ МНЕ ???
В моем приложении я хочу показывать уведомление, и для этого я использовал службу сообщений FireBase.
Я пишу ниже коды под android 8 показывать уведомление, но выше android 8 не показывать никаких уведомлений!
Я знаю, что для показа уведомлений выше, чем android 8, я должен использовать ChannelID и я пишу кодыдля этого, но не показывать никаких уведомлений!
Класс MyNotificationManager:
public class MyNotificationManager {
private Context mCtx;
private Uri soundUri;
private static MyNotificationManager mInstance;
private Intent intent;
private PendingIntent pendingIntent;
private NotificationManager mNotifyMgr;
public MyNotificationManager(Context context) {
mCtx = context;
}
public static synchronized MyNotificationManager getInstance(Context context) {
if (mInstance == null) {
mInstance = new MyNotificationManager(context);
}
return mInstance;
}
public void displayNotification(String title, String body) {
createNotificationChannel();
// main initialize
soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mNotifyMgr = (NotificationManager) mCtx.getSystemService(NOTIFICATION_SERVICE);
// Get General
intent = new Intent(mCtx, SplashActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
pendingIntent = PendingIntent.getActivity(mCtx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
if (mNotifyMgr != null) {
mNotifyMgr.notify(0, getNotifyBuilder(title, body, pendingIntent).build());
}
}
private NotificationCompat.Builder getNotifyBuilder(String title, String body, PendingIntent pendingIntent) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx, "utp_channel_1")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setSound(soundUri)
.setPriority(Notification.PRIORITY_MAX)
.setAutoCancel(true)
.setContentText(body)
.setContentIntent(pendingIntent);
return mBuilder;
}
private void createNotificationChannel() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "app_channel";
String description = "app_channel_desc";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel("app_channel_id", name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = mCtx.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}
}
Класс MyFireBaseMessagingService:
public class MyFireBaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
showNotify(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
}
private void showNotify(String title, String body) {
MyNotificationManager myNotificationManager = new MyNotificationManager(getApplicationContext());
myNotificationManager.displayNotification(title, body);
}
}
Манифест-коды:
</service>
<service android:name=".utility.firebase.MyFireBaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Как это исправить?