通知不适用于Android oneplus3手机

瓦杰丹·阿里

我具有用于生成通知的功能。我还根据oreo要求更新了代码。这里可能是什么问题。感谢您的任何帮助。该帮助在其他所有手机上均有效。我也重新检查了通知设置

private void sendNotification(String messageTitle,String messageBody) {
        android.net.Uri sound;
        Intent intent = new Intent(getActivity(), MainActivity.class);
        //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), 0 /* request code */, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        long[] pattern = {500, 500, 500, 500, 500};
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        SharedPreferences demoprefs = getActivity().getSharedPreferences("demo", MODE_PRIVATE);
        demiIsLoggedIn = demoprefs.getBoolean("demo", true);
        if (!demiIsLoggedIn)
            sound = defaultSoundUri;
        else
            sound = null;
        NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(getActivity())
                .setSmallIcon(getActivity().getApplicationInfo().icon)
                .setContentTitle(messageTitle)
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setVibrate(pattern)
                .setLights(Color.BLUE, 1, 1)
                .setSound(sound)
                .setContentIntent(pendingIntent);
        NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            String CHANNEL_ID = "my_channel_01";// The id of the channel.
            CharSequence name = "notification channel";// The user-visible name of the channel.
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
            notificationManager.createNotificationChannel(mChannel);
        }
        notificationManager.notify(12 /* ID of notification */, notificationBuilder.build());
        Log.d("wajdan","oneplus");

    }
а23соколов

尝试NotificationChannel在notificationBuilder中设置

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getActivity().getApplicationContext(), "my_channel_01")
...

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章