Android:OneSignal 如何使用自定义图标或应用程序图标更改通知账单图标? [英] Android: OneSignal how to change Notification bill icon with custom icon or app icon?

查看:98
本文介绍了Android:OneSignal 如何使用自定义图标或应用程序图标更改通知账单图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

收到通知时,会显示账单图标,而不是应用程序图标或自定义图标,我将其覆盖以从代码中显示.我可以从仪表板更改图标,但我想从代码中处理它

When notification is received the bill icon is shown instead of app icon or custom icon that i override it to be shown from code. i could to change the icon from the dashboard but i want to handle it from the code

内化

    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 以创建正确的尺寸并确保在您的设备上尝试之前看起来正确.

You need to create a icon named ic_stat_onesignal_default in your drawables directory which will be shown instead of OneSignal's default bell icon. It is recommend to use the Android Asset Studio to create the correct sizes and to make sure it will look correct before trying it on your device.

请注意,应用图标不应再用作小通知图标,因为在 Android 5.0 Lollipop 中只会使用图标的 alpha.在这种情况下,大多数应用图标将只是一个白色的乡绅或圆圈.

Note the app icon should no longer be used as a small notification icon as in Android 5.0 Lollipop the icon's alpha will only be used. Most app icons will just be a white squire or circle in this case.

有关更多详细信息,请参阅下面的 OneSignal 文档页面.https://documentation.onesignal.com/docs/customize-notification-icons

See OneSignal's documentation page below for more details. https://documentation.onesignal.com/docs/customize-notification-icons

这篇关于Android:OneSignal 如何使用自定义图标或应用程序图标更改通知账单图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆