【发布时间】:2013-04-06 01:26:35
【问题描述】:
我正在尝试多种解决方案,但都需要用户交互来设置动态壁纸(我不希望用户交互),我只想在第一次运行应用程序时自动设置它意味着安装后并不总是在打开时通过优先记录来完成的应用程序。
我使用以下代码来实现它,但它需要用户交互。
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();
}
}
如果有什么方法请指教,谢谢
【问题讨论】: