adb命令操作手机各种开关

打开iqoo手机热点设置

复制代码
adb shell am start -n com.android.settings/com.android.settings.Settings$\VivoTetherSettingsActivity

蓝牙模块


检查蓝牙状态的ADB命令

检查蓝牙开关状态
bash 复制代码
adb shell settings get global bluetooth_on

开启和关闭蓝牙

使用Intent操作蓝牙(可能会弹出请求提示框)
开启蓝牙
bash 复制代码
adb shell am start -a android.bluetooth.adapter.action.REQUEST_ENABLE
关闭蓝牙
bash 复制代码
adb shell am start -a android.bluetooth.adapter.action.REQUEST_DISABLE

检查蓝牙详细信息

bash 复制代码
adb shell dumpsys bluetooth

获取已配对设备列表

bash 复制代码
adb shell service call bluetooth_manager 6

开启蓝牙扫描(发现新设备)

bash 复制代码
adb shell am startservice -n com.android.bluetooth/.btservice.AdapterService --es command start_discovery

停止蓝牙扫描

bash 复制代码
adb shell am startservice -n com.android.bluetooth/.btservice.AdapterService --es command cancel_discovery

连接到蓝牙设备(需要目标设备的MAC地址)

bash 复制代码
adb shell am startservice -n com.android.bluetooth/.btservice.AdapterService --es command connect --es device XX:XX:XX:XX:XX:XX

断开蓝牙设备(需要目标设备的MAC地址)

bash 复制代码
adb shell am startservice -n com.android.bluetooth/.btservice.AdapterService --es command disconnect --es device XX:XX:XX:XX:XX:XX

设置蓝牙设备可见时间

bash 复制代码
adb shell am start -a android.bluetooth.adapter.action.REQUEST_DISCOVERABLE --ei android.bluetooth.adapter.extra.DISCOVERABLE_DURATION 300

获取蓝牙MAC地址

bash 复制代码
adb shell service call bluetooth_manager 10

检查蓝牙状态(详细信息)

bash 复制代码
adb shell dumpsys bluetooth_manager | grep 'enabled:'

直接调用蓝牙管理器

bash 复制代码
adb shell service call bluetooth_manager 6  # 打开蓝牙
adb shell service call bluetooth_manager 8  # 关闭蓝牙

使用Root权限操作蓝牙(无需弹出提示框)

开启蓝牙
bash 复制代码
adb root
adb shell "svc bluetooth enable"
关闭蓝牙
bash 复制代码
adb root
adb shell "svc bluetooth disable"

编写具有系统权限的Android应用程序操作蓝牙

1. 在AndroidManifest.xml中添加权限
xml 复制代码
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.bluetoothcontrol">

    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
    
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
2. 在MainActivity中添加蓝牙控制代码
java 复制代码
import android.bluetooth.BluetoothAdapter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    private BluetoothAdapter bluetoothAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        Button enableButton = findViewById(R.id.enableButton);
        Button disableButton = findViewById(R.id.disableButton);

        enableButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                enableBluetooth();
            }
        });

        disableButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                disableBluetooth();
            }
        });
    }

    private void enableBluetooth() {
        if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled()) {
            bluetoothAdapter.enable();
        }
    }

    private void disableBluetooth() {
        if (bluetoothAdapter != null && bluetoothAdapter.isEnabled()) {
            bluetoothAdapter.disable();
        }
    }
}
3. 添加按钮到布局文件
xml 复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp">

    <Button
        android:id="@+id/enableButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Enable Bluetooth" />

    <Button
        android:id="@+id/disableButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Disable Bluetooth" />

</LinearLayout>
4. 编译并安装具有系统权限的应用程序
  • 将应用程序签名为系统应用(这通常需要访问设备的系统签名密钥)。
  • 将应用程序安装到设备上的系统分区中(通常需要root权限)。

使用Tasker和AutoInput插件(需Root权限)

安装Tasker和AutoInput插件
  • 从Google Play商店安装Tasker和AutoInput插件。
创建Tasker任务
  • 创建一个新的Tasker任务,使用AutoInput插件自动点击"允许"按钮。
触发Tasker任务
  • 设置触发器,例如通过ADB命令触发Tasker任务来开启或关闭蓝牙。

热点模块


方法一:

复制代码
adb shell am start -n com.android.settings/com.android.settings.Settings$\VivoTetherSettingsActivity
相关推荐
wulechun9 天前
打造你的专属机器宠物:Py-Apple低成本四足机器人开源项目深度解析与全流程DIY实战指南
智能手机
2601_954706499 天前
云手机技术详解+Python实战调用|2026高稳云手机平台推荐
开发语言·python·智能手机
百度搜知知学社9 天前
贝格手机罗盘2.8版:精准导航与功能升级全解析
智能手机·功能升级·手机罗盘·导航应用·版本解析
xsc-xyc9 天前
用 Tailscale + Syncthing 实现手机、电脑与 NAS 的跨网络文件同步
linux·网络·网络安全·智能手机·电脑
wulechun9 天前
打造全栈人工智能知识图谱:深入解析Ai-Learn开源学习路线与实战资源导航指南
智能手机
wulechun9 天前
从深度研究到全能执行:深度解析字节跳动DeerFlow开源超级智能体框架的架构原理与实战部署指南
智能手机
想你依然心痛10 天前
手机远程控制电脑教程:安卓iOS远程桌面推荐、免费工具配置与远程办公技巧
android·智能手机·电脑
开开心心_Every10 天前
近200个工具的电脑故障修复合集
linux·运维·服务器·leetcode·智能手机·电脑·模拟退火算法
私人珍藏库10 天前
[Android] OldRoll复古胶片相机高级版-徕卡-哈苏-宝丽来等等
数码相机·智能手机·app·工具·软件·多功能
2601_9547064910 天前
云手机基础认知、环境配置与自动化实操代码
大数据·智能手机