Start a live wallpaper service from activity

百般思念 提交于 2019-12-22 11:33:41

问题


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);
        }
     });
    }

}

I just want to know if I can start a live wallpaper Service from Activity. I have tried to use Intent but it does not work. Some Designers want me to make a shortcut for Live wallpaper so the user can change their live wallpaper whenever they want :(


回答1:


 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);``



回答2:


There does not seem to be any way to programmatically change the user's lwp.



来源:https://stackoverflow.com/questions/9081258/start-a-live-wallpaper-service-from-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!