Within the app, I call an intent to open the Android Native Live Wallpaper Preview Screen like this:
val intent = Intent( WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER )
intent.putExtra( WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
ComponentName(
this,
RendererWallpaperService::class.java
)
)
intent.putExtra( "testtt", 123 )
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
startActivity( intent )
And my RendererWallpaperService looks like this:
class RendererWallpaperService : WallpaperService()
{
private var inputSensory : InputSensory?= null
override fun onCreateEngine(): Engine
{
return GLESEngine()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
return super.onStartCommand(intent, flags, startId)
}
override fun onCreate() {
super.onCreate()
}
internal inner class GLESEngine : GLEngine()
{
....
}
}
The problem is that I can’t access the ‘testtt‘ Extra from the intent from within the RendererWallpaperService. The getIntent method is available in Activity and since this is an WallpaperService class, there’s no such method.
I was hoping to get the intent from the onStartCommand, but it never gets called ether (but the wallpaper works).
All I want to do is to be able to distinguish if the Native Live Wallpaper Screen was called from within the app or from Android->Live Wallpapers section. I was hoping to simply pass the flag over the intent and that way I would know it was called from the app, otherwise if this flag is missing, then user opened the wallpaper through the android native UI.
How can I read the value from the intent or maybe there’s a better way to determinate if the RendererWallpaperService was ran from the app itself or from native android wallpaper selection screen? Thank you!
>Solution :
Here’s an easy hack:
private val changeWasOurs = false
class RendererWallpaperService : WallpaperService()
{
companion object {
fun setWasOurs() {
changeWasOurs = true
}
}
}
The variable will be set to true when it was our change, and you can then skip it. Remember to set the variable to false when done with each onStartCommand.