//获取已连接蓝牙设备电量
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import java.util.Set;
// 获取默认的蓝牙适配器
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// 创建 StringBuilder 存储结果
StringBuilder resultBuilder = new StringBuilder();
// 如果蓝牙适配器不为空且已启用
if (bluetoothAdapter != null && bluetoothAdapter.isEnabled()) {
// 获取已绑定的设备集合
Set connectedDevices = bluetoothAdapter.getBondedDevices();
// 检查是否找到连接的设备
if (!connectedDevices.isEmpty()) {
// 遍历已绑定的设备
for (BluetoothDevice device : connectedDevices) {
// 如果设备已连接
if (device.isConnected()) {
// 获取该设备的地址
String connectedDeviceAddress = device.getAddress();
// 通过设备地址获取远程设备
BluetoothDevice connectedDevice = bluetoothAdapter.getRemoteDevice(connectedDeviceAddress);
// 获取设备的电池电量
int batteryLevel = connectedDevice.getBatteryLevel();
// 构建设备信息字符串
String deviceInfo = "设备名称: " + connectedDevice.getName() + "\n" +
"设备地址: " + connectedDevice.getAddress() + "\n";
// 检查是否成功获取到电池电量
if (batteryLevel != -1) {
// 添加电池电量信息
deviceInfo += "电池电量: " + batteryLevel + "%\n";
} else {
// 添加电池电量获取失败信息
deviceInfo += "电池电量获取失败\n";
}
// 添加设备信息到结果
resultBuilder.append(deviceInfo).append("\n");
}
}
} else {
// 没有连接的设备
resultBuilder.append("没有连接蓝牙设备。\n");
}
} else {
// 蓝牙适配器为空或未启用
resultBuilder.append("蓝牙未启用或适配器不可用。\n");
}
// 输出结果
return resultBuilder.toString();function isDeviceMoving(threshold, durationMs) {
var Thread = java.lang.Thread;
var context = android.app.ActivityThread.currentApplication().getApplicationContext();
var sensorManager = context.getSystemService(android.content.Context.SENSOR_SERVICE);
var gyroSensor = sensorManager.getDefaultSensor(android.hardware.Sensor.TYPE_GYROSCOPE);
var motionDetected = false;
var listener = new android.hardware.SensorEventListener({
onSensorChanged: function(event) {
var x = event.values[0];
var y = event.values[1];
var z = event.values[2];
var magnitude = Math.sqrt(x*x + y*y + z*z);
if(magnitude > threshold) {
motionDetected = true;
}
},
onAccuracyChanged: function(sensor, accuracy) {}
});
sensorManager.registerListener(listener, gyroSensor, android.hardware.SensorManager.SENSOR_DELAY_NORMAL);
Thread.sleep(durationMs);
sensorManager.unregisterListener(listener);
return motionDetected;
}
// 示例调用:阈值 0.1 rad/s,检测 5 秒
isDeviceMoving(0.1, 5000);判断设备是否处于运动状态
import java.net.HttpURLConnection;
import java.net.URL;
// 创建一个URL对象,指向百度网站
URL url = new URL("https://baidu.com");
// 打开一个HTTP连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// 设置HTTP请求方法为GET
connection.setRequestMethod("GET");
// 设置连接超时时间为1秒
connection.setReadTimeout(1000); // 1秒
// 获取HTTP响应码
int responseCode = connection.getResponseCode();
// 如果收到的状态码不是在400-499范围内,则输出网络连接正常
if (responseCode < 400 || responseCode >= 500) {
("网络连接正常");
}#mvel
// 原低优先级类型(仅悬浮窗,受权限/层级限制)
// 最高优先级类型:突破悬浮窗限制,可覆盖锁屏、状态栏、通知栏
// 解除布局边界限制:允许视图延伸到状态栏/导航栏区域显示
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY// 最高优先级类型:突破悬浮窗限制,可覆盖锁屏、状态栏、通知栏
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;// 解除布局边界限制:允许视图延伸到状态栏/导航栏区域显示
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;//微信快捷启动(bizshortcut方式1)
//微信聊天页面启动(带等待/重启,公众号)
//微信聊天页面启动(指定模式,个人号)
//微信快捷启动(bizshortcut方式2,指定组件+启动旗标)
//微信聊天页面启动(带flags参数)
#微信聊天页面启动 #shell
am start "intent:#Intent;action=com.tencent.mm.action.BIZSHORTCUT;B.LauncherUI.From.Biz.Shortcut=true;S.LauncherUI.Shortcut.Username=wxid;end";//微信聊天页面启动(带等待/重启,公众号)
am start -W -S -n com.tencent.mm/.ui.chatting.ChattingUI --es Chat_User gh_;//微信聊天页面启动(指定模式,个人号)
am start -n com.tencent.mm/com.tencent.mm.ui.chatting.ChattingUI --ei Chat_Mode 1 --es Chat_User wxid;//微信快捷启动(bizshortcut方式2,指定组件+启动旗标)
am start "intent:#Intent;action=com.tencent.mm.action.BIZSHORTCUT;launchFlags=0x10000000;component=com.tencent.mm.plugin.base.stub.WXEntryActivity;B.LauncherUI.From.Biz.Shortcut=true;S.LauncherUI.Shortcut.Username=wxid;end";//微信聊天页面启动(带flags参数)
am start -n com.tencent.mm/.ui.chatting.ChattingUI --es Chat_User wxid -f 0x14000000;#微信聊天页面启动 #shell
//判断热点状态
//判断GPS状态
//判断NFC状态
//数据状态
//蓝牙
//WiFi状态
//是否处于通话中
//获取飞行模式状态
#mvel
import android.content.Context;
import android.net.wifi.WifiManager;
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
return wifiManager.isWifiApEnabled();//判断GPS状态
import android.location.LocationManager;
locationManager = context.getSystemService(context.LOCATION_SERVICE);
boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);//判断NFC状态
import android.nfc.NfcAdapter;
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter();
boolean isEnabled = nfcAdapter != null && nfcAdapter.isEnabled();
return isEnabled;//数据状态
import android.content.Context;
import android.telephony.TelephonyManager;
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
boolean isDataEnabled = telephonyManager.getDataEnabled();//蓝牙
import android.bluetooth.BluetoothAdapter;
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
boolean isBluetoothEnabled = bluetoothAdapter.isEnabled();//WiFi状态
import android.content.Context;
import android.net.wifi.WifiManager;
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
boolean isWifiEnabled = wifiManager.isWifiEnabled();//是否处于通话中
import android.content.Context;
import android.telephony.TelephonyManager;
telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int callState = telephonyManager.getCallState();
return callState == TelephonyManager.CALL_STATE_OFFHOOK || callState == TelephonyManager.CALL_STATE_RINGING;//获取飞行模式状态
import android.provider.Settings;
int airplaneMode = Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0);
return airplaneMode == 1;#mvel