簡體   English   中英

Android:OneSignal如何使用自定義圖標或應用圖標更改通知帳單圖標?

[英]Android: OneSignal how to change Notification bill icon with custom icon or app icon?

收到通知后,會顯示帳單圖標而不是應用圖標或自定義圖標,我會覆蓋它以顯示代碼。 我可以從儀表板更改圖標,但我想從代碼中處理它

Intilaization

    OneSignal.startInit(this)
            .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)// to hide dialog
            .setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
            .init();

接收器類

  class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler
{
    // This fires when a notification is opened by tapping on it.
    @Override
    public void notificationOpened(OSNotificationOpenResult result)
    {
        OSNotificationAction.ActionType actionType = result.action.type;
        JSONObject data = result.notification.payload.additionalData;
        String customKey;

        Intent intent = new Intent(Roshetta.app, SplashActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);


        int requestCode = 0;

            PendingIntent pendingIntent = PendingIntent.getActivity(Roshetta.app, requestCode, intent, PendingIntent.FLAG_ONE_SHOT);
            Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);

            android.support.v4.app.NotificationCompat.Builder noBuilder = new android.support.v4.app.NotificationCompat.Builder(Roshetta.app)
                    .setSmallIcon(R.mipmap.ic_launcher).setLargeIcon(largeIcon).setContentTitle(result.notification.payload.title)
                    .setContentText(result.notification.payload.body )
                    .setAutoCancel(true).setDefaults(android.app.Notification.DEFAULT_ALL)
                    .setContentIntent(pendingIntent).setSound(sound);


            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
             notificationManager.notify(0, noBuilder.build()); //0 = ID of notification


            if (data != null)
            {
                customKey = data.optString("customkey", null);
                if (customKey != null)
                    Log.i("OneSignalExample", "customkey set with value: " + customKey);
            }

            if (actionType == OSNotificationAction.ActionType.ActionTaken)
                Log.i("OneSignalExample", "Button pressed with id: " + result.action.actionID);


            Log.i("OneSignalExample", "ExampleNotificationOpenedHandler");

}

您需要在drawables目錄中創建一個名為ic_stat_onesignal_default的圖標,該圖標將顯示而不是OneSignal的默認響鈴圖標。 建議您使用Android Asset Studio創建正確的尺寸,並確保它在您的設備上嘗試之前看起來正確。

請注意,應用圖標不應再用作Android 5.0 Lollipop中的小型通知圖標,只會使用圖標的alpha。 在這種情況下,大多數應用程序圖標只是一個白色的鄉紳或圈子。

有關詳細信息,請參閱下面的OneSignal文檔頁面。 https://documentation.onesignal.com/docs/customize-notification-icons

您必須為以下尺寸創建圖標:

drawable-hdpi/ic_stat_one_signal_default.png

drawable-mdpi/ic_stat_one_signal_default.png

drawable-xhdpi/ic_stat_one_signal_default.png

drawable-xxhdpi/ic_stat_one_signal_default.png

drawable-xxxhdpi/ic_onesignal_large_icon_default.png

請注意,drawable-xxxhdpi大小的名稱是不同的。

我建議使用Android Asset StudioAndroid Studio-> app-> Image Asset創建圖標,以確保擁有不同Android版本的圖標。

如果要輸入兩個圖標 ,一個用於通知區域,另一個用於通知抽屜,則必須執行以下操作:

1.-為不同尺寸創建相同的圖像圖標: mdpihdpixhdpixxhpi調用: ic_stat_one_signal_default

2.-為xxxhdpi大小創建一個名為ic_onesignal_large_icon_default的不同圖像圖標

看起來像: 圖標 - 通知區域/抽屜

有關更多信息,請參閱OneSignal的官方文檔。 https://documentation.onesignal.com/docs/customize-notification-icons

暫無
暫無

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

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