开始从活动现场壁纸服务 [英] Start a live wallpaper service from activity

查看:121
本文介绍了开始从活动现场壁纸服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 公共类ShortCurActivity延伸活动{

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

    最后Button按钮=(按钮)findViewById(R.id.b_start);
    如果(按钮!= NULL){
     button.setOnClickListener(新View.OnClickListener(){

        公共无效的onClick(查看paramView){
            意图I =新的意图(ShortCurActivity.this,ServiceWallpaper.class);
                     startService(ⅰ);
        }
     });
    }

}
 

我只是想知道我是否可以从活动启动现场壁纸服务。我曾尝试使用意图,但它不工作。有些设计师想让我做了动态壁纸的快捷方式,使用户可以改变他们的动态壁纸,每当他们想要的:(

解决方案

 如果(Build.VERSION.SDK_INT→15)
            {
                i.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
                字符串PKG = WallpaperService.class.getPackage()的getName()。
                字符串CLS = WallpaperService.class.getCanonicalName();
                i.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,新的组件名称(PKG,CLS));
            }
            其他
            {
                i.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
            }
            startActivityForResult(ⅰ,0);``
 

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 :(

解决方案

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

这篇关于开始从活动现场壁纸服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆