1

私は複数のソリューションを試していますが、すべてがライブ壁紙を設定するためにユーザーの操作を必要としています (ユーザーの操作は必要ありません)。アプリケーションの最初の実行時にのみ自動的に設定したい場合は、インストール直後にアプリを開くとは限りません。優先的に記録を保持することによって行われます。

次のコードを使用してそれを実現しましたが、ユーザーの操作が必要です。

    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();
        }
    }

これを行う方法があれば教えてください、ありがとう

4

1 に答える 1