android - 从 Activity 启动动态壁纸服务

标签 android service android-service live-wallpaper android-activity

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/

相关文章:

java - Android - MediaPlayer 崩溃

java - 如何在 Android Studio 中创建 Java 类而不是 C++ 类?

service - 在 Play 应用程序中启动时调用服务

javascript - Controller <-> 服务交互和单元测试 : Am I doing this wrong?

java - 改造发送 Pojo 作为表单数据

c# - Windows 服务 : using of BitmapEncoder or BitmapDecoder ends with «The operation completed successfully»

java - 在初始化类成员之前调用方法

android - 默认情况下在 "allow"中设置 "Asus auto start manager"权限

android - 蓝牙 LE 设备发现服务

Android 自动备份冲突解决