Wallpaper Manager Tutorial

Published on October 20, 2022

A user has messaged me on Telegram for how to do this. This tutorial shows you how to create your very own Wallpaper extension. I have provided the files that you may use at the end of the tutorial.

This tutorial assumes you have at least a little bit of understanding for Rapid by reading previous posts. Do note that this tutorial does not work with the Companion of App Inventor, since it does not declare the wallpaper permission in its manifest.

🏷️ Tags: #extensions, #tutorials-and-guides

A. Create your project.

The first thing you should do is to create your project. Avoid using any of these names, as they are already Java classes and your extension might crash or fail to be compiled.

WallpaperColors, WallpaperInfo, WallpaperManager, WallpaperService

B. Editing the Manifest.

Before anything, after you have created your project, go to Project > Settings, then at the top bar, locate the MANIFEST tab and open it.

You will see an XML file code opened for you. This is the AndroidManifest.xml file of your project. An Android manifest file declares some of the basic properties of your app, such as, what permissions it use.

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example"

android:versionCode="1"

android:versionName="1.0" >

<application>

<!-- Define activities, services, and content providers here-->

</application>

</manifest>

We will add a line before the <application> tag that declares that our extension uses the wallpaper permission.

<uses-permission android:name="android.permission.SET_WALLPAPER"/>

The full code then becomes:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example"

android:versionCode="1"

android:versionName="1.0" >

<uses-permission android:name="android.permission.SET_WALLPAPER"/>

<application>

<!-- Define activities, services, and content providers here-->

</application>

</manifest>

Great! Don’t forget to SAVE it at the bottom right corner of your screen.

C. Importing and defining.

You will have to import the following classes (arranged in alphabetical order for you):

Also, no matter what block you are choosing to implement in your extension, as long as it has something to do with Wallpapers, you must add the following:

D. Clear wallpaper.

This block clears the wallpaper of your phone, both lock screen and home screen. Will not work for versions below Android 9.

Every Context has a wallpaper manager. We can’t create a wallpaper manager class, we get it from the context.

E. Set home screen wallpaper.

The first thing is to add these blocks.

What it does is that it first gets the Bitmap image from the absolute path, then it tries to set the wallpaper to the bitmap.

As explained here (thank you Mohamed), when you create a “try catch” block, it automatically creates a new method block for you to Handle the Error.

Now add this:

To get the "Error with: message" block, right-click on the event that you have created and choose “Create ‘Error’”.

This block requires an absolute path. If you are using it in App Inventor, one of my favorite techniques is adding it into the Assets and using this:

Tests

Tests conducted on Xiaomi 11 5G NE operating on Android 12 in APK.