public class ShortCurActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button)findViewById(R.id.b_start);
if(button != null){
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View paramView) {
Intent i = new Intent(ShortCurActivity.this, ServiceWallpaper.class);
startService(i);
}
});
}
}
我只是想知道是否可以从 Activity 启动动态壁纸服务。我尝试过使用Intent,但它不起作用。一些设计师希望我为动态壁纸创建一个快捷方式,以便用户可以随时更改他们的动态壁纸:(
最佳答案
if (Build.VERSION.SDK_INT > 15)
{
i.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
String pkg = WallpaperService.class.getPackage().getName();
String cls = WallpaperService.class.getCanonicalName();
i.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(pkg, cls));
}
else
{
i.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
}
startActivityForResult(i, 0);``
关于android - 从 Activity 启动动态壁纸服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9081258/