0

我在远程视图的通知中使用滑行。当我更新我的通知时,在某些时候我收到了这样的错误。

    com.bumptech.glide.load.engine.CallbackException: Unexpected exception thrown by non-Glide code
        at com.bumptech.glide.load.engine.EngineJob.callCallbackOnResourceReady(EngineJob.java:160)
        at com.bumptech.glide.load.engine.EngineJob$CallResourceReady.run(EngineJob.java:424)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8125)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
     Caused by: java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 667696 bytes
        at android.app.NotificationManager.notifyAsUser(NotificationManager.java:518)
        at android.app.NotificationManager.notify(NotificationManager.java:449)
        at com.bumptech.glide.request.target.NotificationTarget.update(NotificationTarget.java:123)
        at com.bumptech.glide.request.target.NotificationTarget.setBitmap(NotificationTarget.java:139)
        at com.bumptech.glide.request.target.NotificationTarget.onResourceReady(NotificationTarget.java:129)
        at com.bumptech.glide.request.target.NotificationTarget.onResourceReady(NotificationTarget.java:22)
        at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:631)
        at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:575)
        at com.bumptech.glide.load.engine.EngineJob.callCallbackOnResourceReady(EngineJob.java:158)
        at com.bumptech.glide.load.engine.EngineJob$CallResourceReady.run(EngineJob.java:424) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:237) 
        at android.app.ActivityThread.main(ActivityThread.java:8125) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 
     Caused by: android.os.TransactionTooLargeException: data parcel size 667696 bytes
        at android.os.BinderProxy.transactNative(Native Method)
        at android.os.BinderProxy.transact(BinderProxy.java:575)
        at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:2915)
        at android.app.NotificationManager.notifyAsUser(NotificationManager.java:515)
        at android.app.NotificationManager.notify(NotificationManager.java:449) 
        at com.bumptech.glide.request.target.NotificationTarget.update(NotificationTarget.java:123) 
        at com.bumptech.glide.request.target.NotificationTarget.setBitmap(NotificationTarget.java:139) 
        at com.bumptech.glide.request.target.NotificationTarget.onResourceReady(NotificationTarget.java:129) 
        at com.bumptech.glide.request.target.NotificationTarget.onResourceReady(NotificationTarget.java:22) 
        at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:631) 
        at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:575) 
        at com.bumptech.glide.load.engine.EngineJob.callCallbackOnResourceReady(EngineJob.java:158) 
        at com.bumptech.glide.load.engine.EngineJob$CallResourceReady.run(EngineJob.java:424) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:237) 
        at android.app.ActivityThread.main(ActivityThread.java:8125) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 

我认为通知中的滑行图像正在发生这种情况。所以我搜索了这个并修改了我的代码以不创建但更新我的通知。即使我更新了通知,结果也是一样的。但是有很多关于在通知中使用图像的情况。有没有这方面的参考?

这是我的代码。

    fun createNotification(context: Context, musicData: PlayListEntity, player: SimpleExoPlayer): Notification {
        notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        val resultIntent = Intent(context, MainActivity::class.java)
        resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
        val resultPendingIntent: PendingIntent? = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_CANCEL_CURRENT)
        notification = getNotificationBuilderInstance(context,musicData, player).build()

        val target = NotificationTarget(context,  binding!!.notiAlbumImage.id, contentView, notification, NOTIFICATION_ID)

        Glide.with(context.applicationContext)
            .asBitmap()
            .load(musicData.imageUrl)
            .error(R.drawable.close_button)
            .into(target)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val channelName = "Music Channel"
            val channel = NotificationChannel(CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_DEFAULT)
            notificationManager?.createNotificationChannel(channel)
        }
        return notification!!
    }

    fun updateNotification(context: Context,musicData: PlayListEntity, player: SimpleExoPlayer) {
        contentView!!.setTextViewText(binding!!.notiMusicName.id, musicData.title)
        val target = NotificationTarget(context, binding!!.notiAlbumImage.id, contentView,
            notification, NOTIFICATION_ID)
        if (player.playWhenReady) {
            contentView!!.setImageViewResource(binding!!.playButton.id, R.drawable.pause_button)
        } else {
            contentView!!.setImageViewResource(binding!!.playButton.id, R.drawable.play_button)
        }
        Glide.with(context.applicationContext)
            .asBitmap()
            .load(musicData.imageUrl)
            .error(R.drawable.close_button)
            .into(target)

        if(musicData.musicId!=musicService?._musicList?.value!![musicService?._currentPlayPosition!!.value!!].musicId){
            musicService?.updateNotification()
            return
        }
        notificationManager?.notify(NOTIFICATION_ID, notification)
    }
4

0 回答 0