codenameakshay / async_wallpaper

https://pub.dev/packages/async_wallpaper
MIT License
22 stars 19 forks source link

Invoking setWallpaper inside workmanager yields PlaformException #15

Open innomatica opened 1 year ago

innomatica commented 1 year ago

I want to change the wallpaper in the background at a certain point. WorkManager invokes

AsyncWallpaper.setWallpaperFromFile(localFilePath);

and creates following PlatformException

E/MethodChannel#async_wallpaper(14385): Failed to handle method call
E/MethodChannel#async_wallpaper(14385): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.startActivity(android.content.Intent)' on a null object reference
E/MethodChannel#async_wallpaper(14385):     at com.codenameakshay.async_wallpaper.AsyncWallpaperPlugin.home(AsyncWallpaperPlugin.java:158)
E/MethodChannel#async_wallpaper(14385):     at com.codenameakshay.async_wallpaper.AsyncWallpaperPlugin.onMethodCall(AsyncWallpaperPlugin.java:210)
E/MethodChannel#async_wallpaper(14385):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#async_wallpaper(14385):     at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#async_wallpaper(14385):     at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#async_wallpaper(14385):     at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#async_wallpaper(14385):     at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#async_wallpaper(14385):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#async_wallpaper(14385):     at android.os.Looper.loopOnce(Looper.java:201)
E/MethodChannel#async_wallpaper(14385):     at android.os.Looper.loop(Looper.java:288)
E/MethodChannel#async_wallpaper(14385):     at android.app.ActivityThread.main(ActivityThread.java:7839)
E/MethodChannel#async_wallpaper(14385):     at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#async_wallpaper(14385):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/MethodChannel#async_wallpaper(14385):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Any suggestion would be appreciated.

TIA,

Flutter:

Dart:

jjfster commented 8 months ago

Did you ever get this working?

innomatica commented 8 months ago

No I didn't.