1

I am trying multiple solutions but all are requiring user interaction to set the live wallpaper (I don't want user interaction), where I want to set it automatically only on first run of application means right after installation not always on opening the app which is done through keeping record in preference.

I used following code to make it happen but it is requiring user interaction.

    SharedPreferences p = PreferenceManager
            .getDefaultSharedPreferences(this);
    boolean firstRun = p.getBoolean(PREFERENCE_FIRST_RUN, true);
    if (firstRun) {
        p.edit().putBoolean(PREFERENCE_FIRST_RUN, false).commit();

        try {

            Intent intent = new Intent(
                    WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
            ComponentName component = new ComponentName(this,
                    MyWallpaperService.class);

            intent.putExtra(
                    WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
                    component);
            startActivityForResult(intent, 0);

        } catch (Exception e) {
            Toast.makeText(this, "Error setting wallpaper",
                    Toast.LENGTH_SHORT).show();
        }
    }

Please guide me if there is any way of doing this, thanks

4

1 回答 1

0

我不知道这是否是个好主意,但您可以将您的逻辑放在 onCreate() 中。当您的活动开始/启动时,它每次都会被调用。

于 2013-04-05T16:40:34.977 回答