Android 10 Изображение уведомления не отображается. Всегда отображается как стиль уведомления по умолчанию - PullRequest
0 голосов
/ 29 апреля 2020

Я кодирую приложение, которое имеет функцию уведомления. Я реализовал FCM. все было хорошо, но когда я обновился до android 10, уведомление показывается так, как я хочу, чтобы оно всегда показывалось как стиль по умолчанию с простым заголовком и телом. я пытался многое изменить, но каждый раз получал одно и то же.

Даже если я не устанавливаю заголовок и текст, полученный fcm, он по-прежнему отображает заголовок и текст, полученные fcm

Я использовал большое изображение значка, на котором также не отображается

, которое происходит только на android 10, выше, отлично работает в Android 9. Пожалуйста, помогите вот код Фрагмент службы fcm.

служба поддержки сообщений о пожаре. java

public class firebasemessagingservice 
extends FirebaseMessagingService { 
    private Bitmap getBitmapfromUrl(String string2) { 
        try { 
            HttpURLConnection httpURLConnection = (HttpURLConnection)new URL(string2).openConnection(); 
            httpURLConnection.setDoInput(true); 
            httpURLConnection.connect(); 
            Bitmap bitmap = BitmapFactory.decodeStream((InputStream)httpURLConnection.getInputStream()); 
            return bitmap; 
        } 
        catch (Exception exception) { 
            StringBuilder stringBuilder = new StringBuilder(); 
            stringBuilder.append("Error in getting notification image: "); 
            stringBuilder.append(exception.getLocalizedMessage()); 
            Log.e((String)"awesome", (String)stringBuilder.toString()); 
            return null; 
        } 
    } 

    private void sendNotification(String string2, String string3, String string4, String string5) { 
        Intent intent = new Intent((Context)this, dashboard.class); 
        intent.addFlags(67108864); 
        PendingIntent pendingIntent = PendingIntent.getActivity((Context)this, (int)0, (Intent)intent, (int)1073741824); 
        NotificationManager notificationManager = (NotificationManager)this.getSystemService("notification"); 
        if (Build.VERSION.SDK_INT >= 26) { 
            notificationManager.createNotificationChannel(new NotificationChannel("General", (CharSequence)"General", 4)); 
        } 
        Uri uri = RingtoneManager.getDefaultUri((int)2); 
        NotificationCompat.Builder builder = new NotificationCompat.Builder((Context)this, "General").setSmallIcon(2131165441).setContentTitle((CharSequence)string5).setContentText((CharSequence)string5).setAutoCancel(true).setSound(uri).setContentIntent(pendingIntent).setStyle((NotificationCompat.Style)new NotificationCompat.BigTextStyle().bigText((CharSequence)string3)); 
        if (string4 != null) { 
            builder.setLargeIcon(this.getBitmapfromUrl(string4)); 
        } 
        notificationManager.notify(1, builder.build()); 
    } 

    public void onMessageReceived(RemoteMessage remoteMessage) { 
        if (remoteMessage.getData().size() > 0) { 
            StringBuilder stringBuilder = new StringBuilder(); 
            stringBuilder.append("Message data payload: "); 
            stringBuilder.append((Object)remoteMessage.getData()); 
            Log.d((String)"Constraints", (String)stringBuilder.toString()); 
        } 
        if (remoteMessage.getNotification() != null) { 
            StringBuilder stringBuilder = new StringBuilder(); 
            stringBuilder.append("Message Notification Body: "); 
            stringBuilder.append(remoteMessage.getNotification().getBody()); 
            Log.d((String)"Constraints", (String)stringBuilder.toString()); 
        } 
        String string2 = remoteMessage.getNotification().getTitle(); 
        String string3 = remoteMessage.getNotification().getBody(); 
        String string4 = (String)remoteMessage.getData().get((Object)"icon"); 
        String string5 = (String)remoteMessage.getData().get((Object)"body1"); 
        StringBuilder stringBuilder = new StringBuilder(); 
        stringBuilder.append(" icon "); 
        stringBuilder.append(string4); 
        Log.d((String)"Constraints", (String)stringBuilder.toString()); 
        this.sendNotification(string2, string3, string4, string5); 
    } 

    public void onNewToken(String string2) { 
        StringBuilder stringBuilder = new StringBuilder(); 
        stringBuilder.append("Refreshed token: "); 
        stringBuilder.append(string2); 
        Log.d((String)"Constraints", (String)stringBuilder.toString()); 
    } 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...