【问题标题】:android - set live wallpaper on app installandroid - 在应用安装时设置动态壁纸
【发布时间】: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();
        }
    }

如果有什么方法请指教,谢谢

【问题讨论】:

    标签: android live-wallpaper


    【解决方案1】:

    我不知道这是否是个好主意,但您可以将您的逻辑放在 onCreate() 中。 当您的活动开始/启动时,它每次都会被调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多