簡體   English   中英

GCM通知圖標重疊(兩次相同,大小不一)

[英]GCM notification icon overlapping (two times the same icon, small and huge)

我在我的應用程序中使用GCM,通知圖標在android 4.1和4.4設備中似乎還可以,但是在android 5.1中,我可以看到兩個圖標,一個非常小,一個具有正常大小。 小圖標位於右下角,與大圖標重疊。 您可以在此圖片中看到它:

在此處輸入圖片說明

這是我的代碼:

private void generateNotification(String message) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(Constants.COMING_FROM_NOTIFICATION, true);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

        Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        String appName = getResources().getString(R.string.app_name);       

        int width;
        int height;
        if (Util.checkAndroidVersionUpperOrEqualThan(11)){      
            width = getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width); 
            height = getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
        }else{
            width = 64;
            height = 64;
        }

        image = Bitmap.createScaledBitmap(image, width, height, false);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .setLargeIcon(image)
        .setContentTitle(appName)
        .setContentText(message)
        .setSound(defaultSoundUri)
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setContentIntent(pendingIntent)
        .setAutoCancel(true)
        .setCategory(NotificationCompat.CATEGORY_MESSAGE)
        .setStyle(new NotificationCompat.BigTextStyle().bigText(message));

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

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

關於setSmallIcon() Notification class的android文檔指出:

設置小圖標資源,該資源將用於表示狀態欄中的通知。 除非還指定了大圖標,否則展開視圖的平台模板將在左側繪制此圖標,在這種情況下,小圖標將移至右側。

這表示API會以某種方式忽略大圖標。 嘗試刪除要檢查版本的代碼。 不知道為什么會導致這種情況。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM