使用ADB更改Android壁纸?

8
我想知道是否可以使用我的笔记本电脑通过ADB更改安卓壁纸。我不知道是否存在任何相关指令,或者我需要将图片复制到文件夹中或编辑文本文件。如果可能的话,我需要通过ADB解决这个问题。
谢谢!
7个回答

5

您只需启动适当的壁纸设置意图,由已注册接收它的(多个)安装应用程序之一处理:

adb shell am start \
    -a android.intent.action.ATTACH_DATA \
    -c android.intent.category.DEFAULT \
    -d file:///path/to/my/image/on/device.jpg \
    -t 'image/*' \
    -e mimeType 'image/*'

如果你需要先将它上传到你的设备上(bash语法):
file=/tmp/test.jpg
dest=/sdcard/Download/"${file##*/}"
adb push "$file" "$dest"
adb shell am start \
    -a android.intent.action.ATTACH_DATA \
    -c android.intent.category.DEFAULT \
    -d file://"$dest" \
    -t 'image/*' \
    -e mimeType 'image/*'

2

壁纸是通过您的主屏幕应用程序设置的。这可以是任何应用程序,因此不存在通用的adb命令。

我知道像Trebuchet这样的应用程序(Cyanogenmod中默认使用的旧启动器)会从XML / JSON文件加载信息,因此您可以推送图像/配置文件并触发重新启动,但它将特定于您正在使用的主屏幕应用程序。因此,您必须找出您正在使用哪个应用程序以及是否存在任何外部配置文件可以修改。

编辑

我将编写一个小型Android应用程序,该应用程序使用BroadcastReceiver或深度链接到侦听专门的Intent的活动。意图将包括数据,其中包含要用作壁纸的文件位置。然后在应用程序中编写代码,以编程方式设置壁纸。有关该部分的帮助,请参见Programmatically set android phone's background。然后,您可以通过adb发送意图(请参见Sending intent to BroadcastReceiver from adb),您的代码将侦听该意图,并触发更新壁纸。我不会详细介绍如何实现它,但希望为您提供足够的搜索术语,以便知道如何自己实现它。


没问题,但我会告诉你我正在尝试构建什么。我正在为树莓派编写一个脚本,以在手机连接时进行个性化设置,但我需要先访问手机并安装一个应用程序来与树莓派通信。谢谢大家!(对我的糟糕英语感到抱歉) - user5217197

2

壁纸存储在 /data/system/users/USER_ID/wallpaper_info.xml 文件中:

~ # cat /data/system/users/0/wallpaper_info.xml 
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<wp width="1080" height="960" name="" component="net.rocboronat.android.wallpaper.npe/.NPEWallpaper" />

在CWM中挂载/data,然后使用adb shell。要编辑文件,请使用cat > file/to/change,粘贴内容,按^D键。新的内容已经成功保存到文件中。


1

这对我在Android 5.1上有效。

am start -d file:////data/local/tmp/black_white.png -a android.service.wallpaper.CROP_AND_SET_WALLPAPER -f 0x1 com.android.launcher3/.WallpaperCropActivity`

1
假设您的设备正在使用Launcher3 - Blundell

0

位图文件位于/data/system/users/0/wallpaper


0
如果您正在使用亚马逊Fire平板电脑HD 8(第8代)
Fire OS 6.3.0.0
仅更改未锁定壁纸的批处理代码为:
set file=wallpaper.jpg
set dest=/sdcard/Download/%file%
adb push %file% %dest%

adb shell am start -d file://%dest% -a android.service.wallpaper.CROP_AND_SET_WALLPAPER -f 0x1 com.amazon.photos/com.android.launcher3.WallpaperCropActivity

源代码

我找到要使用的命令的方法是使用最近的命令。执行操作,然后转储信息:

adb shell dumpsys activity recents   # for Android 4.4 and above
adb shell dumpsys activity activities # for Android 4.2.1

源代码

或者您可以尝试记录操作,但我认为这仅适用于输入:

adb shell getevent

来源


0

我写了一个应用程序来完成这个任务,因此可以通过ADB完成而无需触摸设备:

adb install the-app.apk
adb shell am broadcast -a com.blundell.app.SET_WALLPAPER -n com.blundell.app/.SetWallpaper
adb uninstall com.blundell.app

应用程序:
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.blundell.app"
    >

    <uses-permission android:name="android.permission.SET_WALLPAPER"/>

    <application
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        tools:ignore="GoogleAppIndexingWarning"
        >
        <receiver
            android:name=".SetWallpaper"
            tools:ignore="ExportedReceiver"
            >
            <intent-filter>
                <action android:name="com.blundell.app.SET_WALLPAPER"/>
            </intent-filter>

        </receiver>
    </application>

</manifest>

没有活动。

广播接收器:

class SetWallpaper : BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent?) {
        WallpaperManager.getInstance(context).setResource(R.raw.wallpaper)
    }
}

就是这样!

壁纸本身存储在/res/raw/目录中。 如果需要,您也可以通过广播意图传递壁纸位置。


1
你好,这里的答案非常有用,但我无法构建应用程序,你能分享一下APK文件吗? - Zubair Younas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接