nativephp/mobile-device
最新稳定版本:0.0.1
Composer 安装命令:
composer require nativephp/mobile-device
包简介
Device hardware operations for NativePHP Mobile
README 文档
README
Device hardware operations including vibration, flashlight, device info, and battery status.
Overview
The Device API provides access to device hardware features and information.
Installation
composer require nativephp/mobile-device
Usage
PHP (Livewire/Blade)
use Native\Mobile\Facades\Device; // Vibrate the device Device::vibrate(); // Toggle flashlight $result = Device::toggleFlashlight(); // Returns: ['success' => true, 'state' => true|false] // Get device ID $result = Device::getId(); // Returns: ['id' => 'unique-device-id'] // Get device info $result = Device::getInfo(); // Returns: ['info' => '{"name":"iPhone","model":"iPhone","platform":"ios",...}'] // Get battery info $result = Device::getBatteryInfo(); // Returns: ['info' => '{"batteryLevel":0.85,"isCharging":false}']
JavaScript (Vue/React/Inertia)
import { device } from '#nativephp'; // Vibrate the device await device.vibrate(); // Toggle flashlight const flashResult = await device.toggleFlashlight(); console.log('Flashlight state:', flashResult.state); // Get device ID const idResult = await device.getId(); console.log('Device ID:', idResult.id); // Get device info const infoResult = await device.getInfo(); const info = JSON.parse(infoResult.info); console.log('Platform:', info.platform); // Get battery info const batteryResult = await device.getBatteryInfo(); const battery = JSON.parse(batteryResult.info); console.log('Battery level:', battery.batteryLevel * 100 + '%');
Methods
vibrate(): array
Vibrate the device.
Returns: { success: true }
toggleFlashlight(): array
Toggle the device flashlight on/off.
Returns: { success: boolean, state: boolean }
getId(): array
Get the unique device identifier.
Returns: { id: string }
- iOS: Uses
identifierForVendorUUID - Android: Uses
ANDROID_ID
getInfo(): array
Get detailed device information.
Returns: { info: string } (JSON string)
Device info includes:
name- Device namemodel- Device modelplatform- "ios" or "android"operatingSystem- OS nameosVersion- OS version stringmanufacturer- Device manufacturerisVirtual- Whether running in simulator/emulatormemUsed- Memory usage in byteswebViewVersion- WebView version
getBatteryInfo(): array
Get battery level and charging status.
Returns: { info: string } (JSON string)
Battery info includes:
batteryLevel- Battery level from 0.0 to 1.0isCharging- Whether device is charging
Permissions
Android
android.permission.VIBRATE- For vibrationandroid.permission.FLASHLIGHT- For flashlight control
iOS
No special permissions required.
License
MIT
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-03