Unable to get settings button to display live wallpaper

I want to add settings to the live wallpapers that I created. I am missing something very fundamental in how SharedPreferences work. The code and XML are based on live cubes, and I cannot understand what I did wrong. My problem is that the "Settings" button does not appear when I select my live wallpapers from the list. Only the "Set Wallpaper" button is displayed. I suspect that I messed up something in XML.

These are very simple live wallpapers that I made to just fool the settings. Everything he does sets the background to both blue and green (and this part works).

I believe the appropriate code and xml should be:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.BGWallpaper"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />
    <uses-feature android:name="android.software.live_wallpaper" />

    <application
        android:icon="@drawable/icon" android:label="@string/AppName">

        <service
            android:icon="@drawable/icon"
            android:label="@string/AppName"
            android:name="com.android.BGWallpaper.BlueGreen"
            android:permission="android.permission.BIND_WALLPAPER" android:debuggable="false">
            <intent-filter android:priority="1">
                <action android:name="android.service.wallpaper.WallpaperService" />
            </intent-filter>
            <meta-data android:name="android.service.wallpaper" android:resource="@xml/bg" />
        </service>
        <activity
            android:label="BGSettings"
            android:name="com.android.BGWallpaper.BGPrefs"
            android:theme="@android:style/Theme.Light.WallpaperSettings"
            android:exported="true">
        </activity>
    </application>
</manifest>

preferences.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
        android:title="Title Preference"
        android:key="BGSettings">
    <ListPreference
            android:key="background"
            android:title="Background Title"
            android:summary="Background Summary"
            android:entries="@array/BackgroundChoices"
            android:entryValues="@array/BackgroundChoices" />
</PreferenceScreen>

bg.xml

<?xml version="1.0" encoding="utf-8"?>
<wallpaper 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:thumbnail="@drawable/icon"/>

BlueGreen.java (wallpaper service)

public class BlueGreen extends WallpaperService 
{
    public static final String strSharedPrefs="BGSettings";

   @Override
    public Engine onCreateEngine() 
    {
         return new BGEngine();
    }

    class BGEngine extends Engine  implements SharedPreferences.OnSharedPreferenceChangeListener
    {
        private SharedPreferences msPrefs;

        private final Runnable mDraw = new Runnable() 
        {
            public void run() 
            {
                draw();
           }
        };

        BGEngine()
        {
            msPrefs = BlueGreen.this.getSharedPreferences(strSharedPrefs, MODE_PRIVATE);
            msPrefs.registerOnSharedPreferenceChangeListener(this);
            onSharedPreferenceChanged(msPrefs, null);
        }
    }
    // ...
}

BGPrefs.java:

public class BGPrefs extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener 
{    
    @Override
    protected void onCreate(Bundle icicle) 
    {
        super.onCreate(icicle);
        getPreferenceManager().setSharedPreferencesName(BlueGreen.strSharedPrefs);
        addPreferencesFromResource(R.xml.preferences);
        getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);    
    }
    // ...
}

, ?

, XML/ . , , ?

+3
1

bg.xml...

<?xml version="1.0" encoding="utf-8"?>
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="something"
    android:thumbnail="@drawable/icon"
    android:description="something"
    android:settingsActivity="com.android.BGWallpaper.BGPrefs">
</wallpaper>

android: settingsActivity - , XML .

:)

+10

Source: https://habr.com/ru/post/1796182/


All Articles