单独的动态壁纸的多种设置

发布于 2024-11-10 14:46:49 字数 2450 浏览 7 评论 0原文

我有两个属于同一应用程序的动态壁纸,我试图为每个动态壁纸设置单独的首选项设置,但我遇到了两个壁纸都使用第一个设置的问题。

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <service
        android:label="first wallpaper"
        android:name="com.package.this1.number1"
        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/source1" />
    </service>

    <service
        android:label="second wallpaper"
        android:name="com.package.this2.number2"
        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/source2" />
    </service>

    <activity android:label="@string/settings"
        android:name=".this1.Settings1"
        android:exported="true"
        android:icon="@drawable/icon">
    </activity>

    <activity android:label="@string/settings"
        android:name=".this2.Settings2"
        android:exported="true"
        android:icon="@drawable/icon">
    </activity>

</application>

我是否错过了一些简单的事情,或者如果不制作两个单独的应用程序就无法做到这一点?

这是我的 Settings1 和 Settings2 类的代码

public class Settings1 extends PreferenceActivity   implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    getPreferenceManager().setSharedPreferencesName(number1.SHARED_PREFS_NAME);
    addPreferencesFromResource(R.xml.this1_settings);
    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}

public class Settings2 extends PreferenceActivity   implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    getPreferenceManager().setSharedPreferencesName(number2.SHARED_PREFS_NAME);
    addPreferencesFromResource(R.xml.this2_settings);
    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}

任何建议将不胜感激。

I have two Live Wallpapers that belong to the same Application and I am trying to have separate Preference settings for each one but I have run into the issue of the first settings being used by both Wallpapers.

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <service
        android:label="first wallpaper"
        android:name="com.package.this1.number1"
        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/source1" />
    </service>

    <service
        android:label="second wallpaper"
        android:name="com.package.this2.number2"
        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/source2" />
    </service>

    <activity android:label="@string/settings"
        android:name=".this1.Settings1"
        android:exported="true"
        android:icon="@drawable/icon">
    </activity>

    <activity android:label="@string/settings"
        android:name=".this2.Settings2"
        android:exported="true"
        android:icon="@drawable/icon">
    </activity>

</application>

Am I missing something simple or is it not possible to do this without making 2 separate applications?

Here's the code of my Settings1 and Settings2 classes

public class Settings1 extends PreferenceActivity   implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    getPreferenceManager().setSharedPreferencesName(number1.SHARED_PREFS_NAME);
    addPreferencesFromResource(R.xml.this1_settings);
    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}

public class Settings2 extends PreferenceActivity   implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    getPreferenceManager().setSharedPreferencesName(number2.SHARED_PREFS_NAME);
    addPreferencesFromResource(R.xml.this2_settings);
    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}

Any advice would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音盲 2024-11-17 14:46:49

Moonblink(Android Tricorder 的创建者)也有一系列名为 Substrate 的动态壁纸。 Substrate 确实将多个壁纸组合到一个包中,并且多个壁纸具有设置活动。我建议你检查一下他的结构。从这里开始 http://code.google.com/p/moonblink/source/browse/
并寻找基板(在行李箱下)。希望这有帮助。

PS 项目主页位于:http://code.google.com/p/moonblink/维基/Substrate

Moonblink (creator of Android Tricorder) also has a collection of live wallpapers called Substrate. Substrate does indeed combine multiple wallpapers into a single package, and more than one of the wallpapers has a settings activity. I suggest you examine his structure. Start here http://code.google.com/p/moonblink/source/browse/
and look for Substrate (under trunk). Hope this helps.

P.S. The project home is here: http://code.google.com/p/moonblink/wiki/Substrate

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文