linlukes / VideoLiveWallpaper

Setting Images or Videos as Wallpaper from Gallery or Camera.
Apache License 2.0
2 stars 0 forks source link

Bug: crashes on registerReceiver inside VideoLiveWallpaperService #1

Closed AndroidDeveloperLB closed 5 months ago

AndroidDeveloperLB commented 5 months ago

It seems you've forgotten to use RECEIVER_NOT_EXPORTED for it.

Should be:

ContextCompat.registerReceiver(..., ContextCompat.RECEIVER_NOT_EXPORTED)

Otherwise it crashes on Android 14 (and maybe before too):

java.lang.SecurityException: com.star.videolivewallpaper: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
at android.os.Parcel.createExceptionOrNull(Parcel.java:3182)
at android.os.Parcel.createException(Parcel.java:3166)
at android.os.Parcel.readException(Parcel.java:3149)
at android.os.Parcel.readException(Parcel.java:3091)
at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5784)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1853)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1793)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1781)
at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:756)
at com.star.videolivewallpaper.service.VideoLiveWallpaperService$VideoEngine.onCreate(VideoLiveWallpaperService.kt:23)
at android.service.wallpaper.WallpaperService$Engine.attach(WallpaperService.java:1534)
at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.doAttachEngine(WallpaperService.java:2552)
at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:2591)
at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:44)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
linlukes commented 5 months ago

@AndroidDeveloperLB Can you fix this?

AndroidDeveloperLB commented 5 months ago

@linpengtian Yes, I already wrote you how to.

linlukes commented 5 months ago

Thank you.

linlukes commented 5 months ago

fixed.

AndroidDeveloperLB commented 5 months ago

@linpengtian You didn't fix it well, because you used registerReceiver that is too new for the API level:

https://developer.android.com/reference/android/content/Context#registerReceiver(android.content.BroadcastReceiver,%20android.content.IntentFilter,%20int)

This will cause a crash on older versions of Android. Instead you should use ContextCompat, or check the version yourself.

Also, BTW, why do you use BootBroadCast to start VideoLiveWallpaperService ? It already starts on its own when the app is set as live wallpaper...