Closed JJdeGroot closed 2 years ago
The app also crashes on Lenovo P2a42 with Android 7 / API 24
android.app.RemoteServiceException: Bad notification posted from package nl.ontoegankelijk: Couldn't create icon: StatusBarIcon(icon=Icon(typ=RESOURCE pkg=nl.ontoegankelijk id=0x7f0f0000) visible user=0 )
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6111)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Please show me how you set the notification icon.
Hi, I think this one is actually caused by the system and not by the HBRecorder library. I did some research and found out it can be caused by certain Android launchers. I did not have a .png alternative for my app icon. When I added a .png app icon the crash no longer happened.
Here is some of the code.
private fun getBitmapFromVectorDrawable(context: Context, drawableId: Int): Bitmap? {
ContextCompat.getDrawable(context, drawableId)?.let { drawable ->
val bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth,
drawable.intrinsicHeight, Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
return bitmap
}
return null
}
private fun getByteArrayFromBitmap(bitmap: Bitmap): ByteArray {
val stream = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
return stream.toByteArray()
}
override fun onViewCreated() {
super.onViewCreated()
recorder = HBRecorder(this, this)
recorder?.setNotificationTitle(getString(R.string.recording_notification_title))
recorder?.setNotificationDescription(getString(R.string.recording_notification_message))
recorder?.setNotificationButtonText(getString(R.string.recording_notification_action))
getBitmapFromVectorDrawable(this, R.drawable.icon_notification)?.let { bitmap ->
val bytes = getByteArrayFromBitmap(bitmap)
recorder?.setNotificationSmallIcon(bytes)
}
}
Ok, closing. I will reply on your other issue.
Describe the bug When starting the screen recorder, it immediately crashes when loading the default notification icon.
Somehow the Demo app does work. The only difference I can find is that it sets the notification icon with a byte array. When I do this, my own app still crashes. Other than changing the notification settings, everything is set to default.
Log
Can it be reproduced in demo app No, it works in the demo app. The demo app does not show a notification. It does show the casting icon.
HBRecorder version 2.0.2
Device information
Screenshots Not applicable