gpt4 book ai didi

android - 错误通知 : The given region must intersect with the Bitmap's dimensions

转载 作者:行者123 更新时间:2023-11-29 02:22:01 26 4
gpt4 key购买 nike

我在 Crashlytics 上遇到了针对少量用户的异常。对于大多数用户来说,它似乎工作正常,但对于某些用户来说它会失败(数量很少,但我现在只是在分阶段发布)。我认为问题可能是我缩小了我在通知中使用的位图,我使用这段代码来缩小它:

bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);

异常(exception)是这样的:

Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package mypacakge: Couldn't inflate contentViewsjava.lang.IllegalArgumentException: The given region must intersect with the Bitmap's dimensions.
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1881)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

我做错了什么?

谢谢。

编辑:我搜索了 Android 代码,看看是谁抛出了那个异常,它似乎是 Palette。生成器,然后我搜索了与使用 Palette 的通知相关的代码和 setRegion()方法并在 MediaNotificationProcessor.java 上找到了这个:

Palette.Builder paletteBuilder = Palette.from(bitmap)
.setRegion(0, 0, bitmap.getWidth() / 2, bitmap.getHeight())
.clearFilters() // we want all colors, red / white / black ones too!
.resizeBitmapArea(RESIZE_BITMAP_AREA);
Palette palette = paletteBuilder.generate();
backgroundColor = findBackgroundColorAndFilter(palette);
// we want most of the full region again, slightly shifted to the right
float textColorStartWidthFraction = 0.4f;
paletteBuilder.setRegion((int) (bitmap.getWidth() * textColorStartWidthFraction), 0,
bitmap.getWidth(),
bitmap.getHeight());
if (mFilteredBackgroundHsl != null) {
paletteBuilder.addFilter((rgb, hsl) -> {
// at least 10 degrees hue difference
float diff = Math.abs(hsl[0] - mFilteredBackgroundHsl[0]);
return diff > 10 && diff < 350;
});
}

所以我的猜测是它在这里传递了一些错误的值,但我不知道是什么。我已经为这个错误添加了更多的 Fabric 日志,希望我能尽快获得更多数据。

最佳答案

这是一个工作代码,希望它能帮助你,或者其他人......

String CHANNEL_ID = "my_channel_xy";
CharSequence name = "my_channel";
String Description = "This is my channel";
int NOTIFICATION_ID = 19920901;

Log.d("FileCreator : ","Notification Creating...:"+NOTIFICATION_ID);

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

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)
{
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
mChannel.setDescription(Description);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100});
mChannel.setShowBadge(true);

if (notificationManager != null)
{
notificationManager.createNotificationChannel(mChannel);
}

}

Intent resultIntent = new Intent(this, MainActivity.class);
resultIntent.putExtra("MYVAR", "MYVAL");
resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

//resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("NextTitle")
.setContentText("NextText")
.setTicker("NextText")
.setStyle(new NotificationCompat.BigTextStyle().bigText("NextMessage it is a long text which is replaced when user swipes it down from the notification tray..."))
.setSmallIcon(R.drawable.ic_mynotification)
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher))
.setPriority(NotificationCompat.PRIORITY_MAX)
.setDefaults(DEFAULT_SOUND | DEFAULT_VIBRATE)
.setContentIntent(resultPendingIntent)
.setAutoCancel(false)
.setOngoing(true)
.setOnlyAlertOnce(true)
.setColor(getResources().getColor(android.R.color.holo_red_dark));

if (notificationManager != null)
{
notificationManager.notify(NOTIFICATION_ID, builder.build());
Log.d("FileCreator : ", "NOTIFIED TO THE USER... \n");
}
else
{
Log.d("FileCreator : ", "COULD NOT BE NOTIFIED TO THE USER...????!!!! \n");
}

这应该适用于所有设备,通知中有两个图标。

关于android - 错误通知 : The given region must intersect with the Bitmap's dimensions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54948936/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com