Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android API eval 26中未收到通知_Android_Firebase - Fatal编程技术网

android API eval 26中未收到通知

android API eval 26中未收到通知,android,firebase,Android,Firebase,我尝试在android Oreo中接收通知。但该应用程序并没有收到任何消息 通知。我还创建了通知香奈儿,但它不起作用 如果我从fcm发送通知,则应用程序已收到。但使用令牌应用程序未收到任何通知。在其他较低版本中,版本通知可以正常工作。在奥利奥,它不起作用 这是我的MyFirebaseMessagingService类: public class MyFirebaseMessagingService extends FirebaseMessagingService { publ

我尝试在android Oreo中接收通知。但该应用程序并没有收到任何消息

通知。我还创建了通知香奈儿,但它不起作用

如果我从fcm发送通知,则应用程序已收到。但使用令牌应用程序未收到任何通知。在其他较低版本中,版本通知可以正常工作。在奥利奥,它不起作用

这是我的MyFirebaseMessagingService类:

     public class MyFirebaseMessagingService extends FirebaseMessagingService {
     public static int NOTIFICATION_ID = 1;
     public static final String NOTIF_CHANNEL_ID = "my_channel_01";


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

        sendNotification(remoteMessage.getData());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            createNotifChannel(this);
        }

     }

     @RequiresApi(api = Build.VERSION_CODES.O)
     private void createNotifChannel(MyFirebaseMessagingService 
     myFirebaseMessagingService)
     {
        NotificationChannel channel = new NotificationChannel(NOTIF_CHANNEL_ID,
                "MyApp events", NotificationManager.IMPORTANCE_LOW);
        // Configure the notification channel
        channel.setDescription("MyApp event controls");

        channel.setShowBadge(false);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

        NotificationManager manager = getApplicationContext().
        getSystemService(NotificationManager.class);

        manager.createNotificationChannel(channel);
        Log.d(TAG, "createNotifChannel: created=" + NOTIF_CHANNEL_ID);
        }

        private void sendNotification(Map<String, String> data) {

        int num = ++NOTIFICATION_ID;
        Bundle msg = new Bundle();
        for (String key : data.keySet()) {
            Log.e(key, data.get(key));
            msg.putString(key, data.get(key));
        }
        Intent intent = new Intent(this, HomeActivity.class);
        if (msg.containsKey("action")) {
            intent.putExtra("action", msg.getString("action"));
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, num /* 
        Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri = 
        RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new 
         NotificationCompat.Builder(this)
                .setSmallIcon(instauser.application.apps.R.drawable.icon)
                .setContentTitle(msg.getString("title"))
                .setContentText(msg.getString("msg"))
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

         NotificationManager notificationManager =
                (NotificationManager) 
         getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(num, notificationBuilder.build());
    }

} 
公共类MyFirebaseMessagingService扩展了FirebaseMessagingService{
公共静态int通知_ID=1;
公共静态最终字符串NOTIF\u CHANNEL\u ID=“my\u CHANNEL\u 01”;
@凌驾
收到消息时公共无效(RemoteMessage RemoteMessage){
super.onMessageReceived(remoteMessage);
sendNotification(remoteMessage.getData());
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.O){
createNotifChannel(此);
}
}
@RequiresApi(api=Build.VERSION\u CODES.O)
私有void createNotifChannel(MyFirebaseMessagingService
myFirebaseMessagingService)
{
NotificationChannel=新的NotificationChannel(NOTIF\u channel\u ID,
“MyApp事件”,NotificationManager。重要性(低);
//配置通知通道
channel.setDescription(“MyApp事件控件”);
频道设置显示卡(假);
channel.setLockscreenVisibility(通知.VISIBILITY\u PUBLIC);
NotificationManager=getApplicationContext()。
getSystemService(NotificationManager.class);
manager.createNotificationChannel(频道);
Log.d(标签,“createNotifChannel:created=“+NOTIF\u CHANNEL\u ID”);
}
私有void sendNotification(地图数据){
int num=++NOTIFICATION_ID;
Bundle msg=新Bundle();
for(字符串键:data.keySet()){
Log.e(key,data.get(key));
msg.putString(key,data.get(key));
}
意向意向=新意向(此,HomeActivity.class);
如果(消息containsKey(“行动”)){
intent.putExtra(“action”,msg.getString(“action”);
}
intent.addFlags(intent.FLAG\u ACTIVITY\u CLEAR\u TOP);
PendingEvent PendingEvent=PendingEvent.getActivity(这个,num/*
请求代码*/,意图,
悬挂式帐篷(一杆旗帜);
Uri defaultSoundUri=
ringtonemager.getDefaultUri(ringtonemager.TYPE_通知);
NotificationCompat.Builder notificationBuilder=新建
NotificationCompat.Builder(此)
.setSmallIcon(instauser.application.apps.R.drawable.icon)
.setContentTitle(msg.getString(“标题”))
.setContentText(msg.getString(“msg”))
.setAutoCancel(真)
.setSound(defaultSoundUri)
.setContentIntent(挂起内容);
通知经理通知经理=
(通知经理)
getSystemService(上下文通知服务);
notificationManager.notify(num,notificationBuilder.build());
}
} 

我还创建了一个通知频道,但它不起作用

您创建了通知频道,但没有将其设置为通知

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        ...
        .setChannelId(NOTIF_CHANNEL_ID)

onMessageReceived
正在调用吗?如果您没有获得您的令牌,那么您可以进行意向服务,并通过使用该服务,您可以获得您的fcm令牌。我可以共享在每个设备上成功运行的代码片段