收到通知后,将显示账单图标,而不是应用程序图标或自定义图标(我将其覆盖以从代码中显示)。我可以从仪表板上更改图标,但是我想从代码中进行处理
全球化
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");
}
您需要ic_stat_onesignal_default
在drawables
目录中创建一个名为图标,而不是OneSignal的默认响铃图标。它是建议使用Android的资产工作室创建正确的大小,并确保它看起来是正确的尝试它您的设备上了。
请注意,应用程序图标应不再作为一个小型的通知图标为的是Android 5.0棒棒糖图标的阿尔法才会使用。在这种情况下,大多数应用程序图标只是一个白色的乡绅或圆圈。
有关更多详细信息,请参见下面的OneSignal文档页。https://documentation.onesignal.com/docs/customize-notification-icons
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句