Androidで壁紙をランダムに表示する

最近、Androidの方をメインに使用し始めて壁紙をランダムに変えたいと思い。
iPhoneではショートカットのアクションでやっていたが、Androidは純正ではそうゆう機能は無いらしい。
AIに聞いたらTaskerってアプリが良いらしいので、入れてみた。
AIの説明では細かいところが違っていたが、なんとかできたのでメモ。
壁紙チェンジャーの作成
Play StoreからTaskerをインストールしました。
バージョンは、6.1.32でした。
手順
- 変数の作成
- タスクの作成
- ファイル一覧の取得
取得したファイル一覧の件数を取得- 取得したファイル一覧の件数取得(変数を設定)
- 選択するファイルの位置をランダムに取得
- ファイル一覧から取り出し
- 壁紙の設定
- 一定時間ごとに繰り返す
変数の作成
変数のタブで+ボタンを押して以下の変数を作成します。
(設定の手順で自動作成されるっぽいのであらかじめ作成しなくてもいいかもしれない)
%FileLength | 画像ファイル数を保持します |
%RandomNumber | 画像ファイル数の中からランダムで選択した位置を保持します |
%Wallpaper | 壁紙に使用する画像のパスを保持します |

※実行後なので値が入っています。
タスクの作成
タスクのタブで+ボタンを押してタスクを作成します


ファイル一覧の取得
タスク編集画面で+ボタンを押してファイル一覧を取得するアクションを追加します。



画像ファイルのディレクトリとファイル一覧を格納する変数名を選択します。順番がわかるようにラベルに番号を入れておきます。

取得したファイル一覧の件数を取得 このやり方では11件しかカウントできない。←(2023/12/23 追記)
タスク編集画面で+ボタンを押してファイル一覧の件数を取得するタスクを追加します。



データに先ほどのファイル一覧を格納した変数(%ImageFiles)を選択、結果の保存先に%FileLengthを選択する。

ファイル一覧の件数を取得(変数を設定) ←(2023/12/23 追記)
タスク編集画面で+ボタンを押して変数を設定するタスクを追加します。
アクションの名前に%FileLength、「これに」にImageFilesを選択して(#)を追加。(#)はリストサイズの意味。



「変数の調査」の上に「変数を設定」を移動する。操作がなかなかうまく行かないが頑張ってドラッグする。「変数の調査」は要らないのではさみマークで削除する。


選択するファイルの位置をランダムに取得
タスク編集画面で+ボタンを押して取得した件数の範囲でランダムの数値を取得するタスクを作成します。



名前に%RandomNumber、最小に1、最大に%FileLengthを指定します。

ファイル一覧から取り出し
タスク編集画面で+ボタンを押してファイル一覧からランダム数値の位置にある画像を取り出すタスクを作成します。



変数の配列に%ImageFiles、位置に%RandomNumber、保存先の変数に%WallPaperを選択します。

壁紙の設定
タスク編集画面で+ボタンを押して壁紙に取り出した画像をセットするアクションを作成します。



種類に全て、画像に%Wallpaperを設定します。


これで、壁紙をランダムで設定するアクションは完成です。プレイボタン▶を押すと実行できます。
エラーなく実行するとタスクの左側に緑の●が付きます。
実行するとファイル件数と選択された画像の位置が変数に入っていることがわかる。←(2023/12/23 追記)



一定時間ごとに繰り返す
プロファイルタブで+ボタンを押して時刻を選択しプロファイルを作成します。



時刻編集で開始を2回タップ、繰り返し1時間、これ以下を2回タップ。
できたプロファイルに壁紙チェンジャーを設定。



これで1時間毎に壁紙がセットされます。
まだ検証中。
壁紙は変わるが、なぜが写真が10枚程度しか選択されていない。。。
検証完了!「変数の設定」のイベントでファイル数は取得できた。←(2023/12/23 追記)