[英]android - set live wallpaper on app install
我正在嘗試多種解決方案,但所有解決方案都需要用戶互動來設置動態壁紙(我不希望用戶互動),在這里我只想在首次運行應用程序時自動設置它,這意味着安裝后並不總是在打開應用程序時通過優先保存記錄來完成。
我使用以下代碼來實現它,但是它需要用戶交互。
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();
}
}
如果有任何方法,請指導我,謝謝
我不知道這是一個好主意,但您可以將邏輯放在onCreate()中。 當您的活動開始/啟動時,每次都會調用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.