Make Interactive Live Video Wallpapers in Kotlin Android
Create interactive live video wallpapers in Android using Kotlin. Learn to implement dynamic backgrounds with smooth performance. Visit rrtutors.com.
Live Wallpapers are animated, interactive backgrounds for the Android home screen. A live wallpaper is similar to other Android applications and will use the same functionality
In this Example we are going to create Live Video Wall Paper
Let's Start
Step 1: Create new project "Live Video Wallpaper"
Step 2: Create VideoWallpaper service and add below code
import android.app.WallpaperManager; import java.io.IOException; public class WallPaper extends WallpaperService { /** /**
class VideoWallpagerEngine extends Engine { @Override @Override @Override try { mMediaPlayer.setDataSource(sVideoPath); } @Override @Override @Override |
Now Configure Service in Manifest file
<service android:name=".WallPaper" android:permission="android.permission.BIND_WALLPAPER" > <intent-filter> <action android:name="android.service.wallpaper.WallpaperService"/> </intent-filter> <meta-data android:name="android.service.wallpaper" android:resource="@xml/videowallpaper" /> </service> |
Here we need to create xml file with below code
videowallpaper.xml
<?xml version="1.0" encoding="utf-8"?>
<wallpaper xmlns:android="https://schemas.android.com/apk/res/android"
android:thumbnail="@mipmap/ic_launcher"
>
</wallpaper>
|
Add below permissions in Manifest file
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
|
Step 3:
Now add Required Resourses for the application, in this application i have added few mp4 files in raw folder
Step 4:
Now Its time to create our UI
updated activity_main
/> android:layout_width="match_parent" android:layout_width="wrap_content" /> /> |
MainActivity.kt
import android.content.Intent import kotlinx.android.synthetic.main.activity_main.view.*;
Glide.with(this).load(R.raw.krish3).diskCacheStrategy(NONE).into(imageview1) imageview1.setOnClickListener(this) override fun onClick(v: View?) { |
Now create SetWallPaperActivity
class WallPaperActivity : AppCompatActivity() { private val IS_VIDEO1: String="is_video1" filename = intent.getStringExtra("filename") private fun initFile() { mFile1 = File(Environment.getExternalStorageDirectory().toString() + "/" + filename) } // videoview.setMediaController(m) } private fun writeMp4ToNative(file: File, istr: InputStream) { try { } fun setWallpaper(view: View) { fun setSilence(view: View) { fun cancelSilence(view: View) { fun toBack(view: View) { private fun checkPermissionForStorage(): Boolean { override fun onRequestPermissionsResult(requestCode: Int, @NonNull permissions: Array, @NonNull grantResults: IntArray) { |
Step 5:
Now run the app and set your wall paper.