facebook twitter hatena line email

Android/ライブ壁紙作成/ライブ壁紙選択画面表示

提供: 初心者エンジニアの簡易メモ
2015年5月20日 (水) 03:13時点における127.0.0.1 (トーク)による版 (ページの作成:「検索しても出てこず4.0で動かすことに苦労した。 android.service.wallpaper.LIVE_WALLPAPER_CHOOSER なんてのがあっのか package info.nonip.andro...」)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

検索しても出てこず4.0で動かすことに苦労した。 android.service.wallpaper.LIVE_WALLPAPER_CHOOSER なんてのがあっのか

package info.nonip.android.lib.util;
import android.content.Intent;
import android.content.Context;
import android.graphics.Bitmap;
import android.app.WallpaperManager;
import android.graphics.drawable.Drawable;
import android.graphics.Canvas;
import android.util.Log;

import java.io.IOException;

/**
 * 壁紙ユーティリティ
 */
public class WallpaperUtil {
  // ライブ壁紙選択を開く
  public static void execOpenLiveSelecter(Context context) {
    try {
      // ライブ壁紙選択ウィンドウを直接表示
      Intent intent = new Intent(Intent.ACTION_MAIN);
      intent.setClassName("com.android.wallpaper.livepicker", "com.android.wallpaper.livepicker.LiveWallpaperListActivity");
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(intent);
Log.d("WallpaperUtil", "type=LiveWallpaperListActivity");
      // ↑だとandroid v4.0系で以下エラーが出る。AndroidManifest.xmlにActivityを追加してもダメでした。
      // android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.wallpaper.livepicker/com.android.wallpaper.livepicker.LiveWallpaperListActivity}; have you declared this activity in your AndroidManifest.xml?
      //   <activity android:name="com.android.wallpaper.livepicker.LiveWallpaperListActivity"
      //     android:label="@string/app_name"
      //     android:theme="@android:style/Theme.NoTitleBar"
      //     android:screenOrientation="nosensor"
      //     android:exported="true"
      //     >
      //     <intent-filter>
      //       <action android:name="android.service.wallpaper.LIVE_WALLPAPER_CHOOSER" />
      //       <action android:name="android.intent.action.SET_WALLPAPER" />
      //       <category android:name="android.intent.category.DEFAULT" />
      //     </intent-filter>
      //   </activity>
    } catch (Exception e) {
      // 壁紙選択画面表示(ライブ壁紙選択のみがまず出る。端末によってはライブ壁紙リストが出る)
      Intent intent = new Intent();
      intent.setAction("android.service.wallpaper.LIVE_WALLPAPER_CHOOSER");
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(intent);
Log.e("WallpaperUtil", "type=LIVE_WALLPAPER_CHOOSER");
    }
  }
  // 壁紙選択を開く
  public static void execOpenSelecter(Context context) {
    // 壁紙選択画面表示(壁紙・ライブ壁紙・端末持壁紙がまず出る)
    Intent intent = new Intent();
    intent.setAction("android.intent.action.SET_WALLPAPER");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
  }
}