- Overview
- Features
- Requirements
- Installation
- Quick Start Guide
- Project Structure
- Configuration
- Usage
- Documentation
- Contributing
- Changelog
- License
- Contact
This demo showcases a simple implementation of cross-device data synchronization using the distributedKVStore module in OpenHarmony. After pairing devices on the same network and verifying a PIN code, the sender device can push messages to the receiver device through a distributed key-value store. The receiver listens for data changes and updates its state accordingly.
UI effects are as follows:
⚠️ Important Note:This example uses system interfaces, so you need to manually replace the Full SDK to compile successfully. For specific steps, refer to the Replacement Guide.
- 🔍 Device Discovery - Discover nearby devices on the same network
- 🔐 Secure Pairing - Authenticate and pair discovered devices using PIN code verification
- 📡 Real-time Sync - Send data from one device to another in real time
- 💾 Distributed KV Store - Utilize OpenHarmony's distributed key-value storage system
- 🔄 Cross-device Communication - Seamless data synchronization across paired devices
- Two OpenHarmony-compatible devices (e.g.,
Dayu200 Development BoardandOpenHarmony Developer Phone) - Valid network connection (both devices must be on the same network)
- OpenHarmony SDK API Level 11 or higher
- DevEco Studio 4.0 or higher
- System-level application privileges
- Valid signature configurations
ACCESS_SERVICE_DM- For device discovery and managementDISTRIBUTED_DATASYNC- For cross-device data synchronization
git clone https://github.com/imansmallapple/app-SuperDeviceDemo.git
cd app-SuperDeviceDemo- Install DevEco Studio
- Replace with Full SDK following the official guide
- Configure system-level application settings (see tutorial)
- Open the project in DevEco Studio
- Ensure you are using API level 11
- Confirm your app is configured as a
system-levelapplication - Sign the application with valid signature configurations
- Connect two OpenHarmony-compatible devices
- Ensure both devices are connected to the same network
- Click the Run button to install the application on both devices
Ensure both devices support OpenHarmony and are connected to the same network.
- On the initiating device, tap the Find Nearby Device button
- Select the target device from the pop-up list
- A verification dialog will appear on the receiver device
- Accept the pairing request on the receiver device
- A random PIN code will be generated and displayed
- Enter the PIN code on the sender device
- Pairing is complete ✅
Once paired:
- The initiating device is automatically labeled as the Sender
- The target device is labeled as the Receiver
- On the Sender device, enter text in the input box
- Tap the Send button to push the message
- The data is synchronized via the distributed KV store
The Receiver device will automatically receive and display the message in real-time.
Tap the Unbind button to disconnect the paired device and reset the session.
app-SuperDeviceDemo/
├── AppScope/ # Application scope configuration
│ ├── app.json5 # Application metadata
│ └── resources/ # Global resources
├── entry/ # Main entry module
│ ├── src/
│ │ ├── main/
│ │ │ ├── ets/
│ │ │ │ ├── entryability/ # Application entry ability
│ │ │ │ ├── pages/ # UI pages
│ │ │ │ ├── utils/ # Utility classes
│ │ │ │ │ ├── DeviceManager.ets # Device management
│ │ │ │ │ ├── kvStoreUtil.ts # KV store operations
│ │ │ │ │ └── Log.ts # Logging utility
│ │ │ │ └── view/ # Custom components
│ │ │ └── resources/ # Module resources
│ │ ├── ohosTest/ # Test files
│ │ └── mock/ # Mock data
│ └── build-profile.json5 # Build configuration
├── hvigor/ # Build tool configuration
├── images/ # Documentation images
├── CHANGELOG.md # Version history
├── LICENSE # Apache 2.0 License
└── README.md # This file
Edit AppScope/app.json5 to modify application metadata:
{
"app": {
"bundleName": "com.example.superdevicedemo",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0"
}
}Required permissions are defined in entry/src/main/module.json5:
{
"requestPermissions": [
{
"name": "ohos.permission.ACCESS_SERVICE_DM"
},
{
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
}
]
}import DeviceManager from '../utils/DeviceManager'
// Discover nearby devices
DeviceManager.discoverDevices()
// Pair with a device
DeviceManager.pairDevice(deviceId)
// Unbind device
DeviceManager.unbindDevice(deviceId)import KvStoreModel from '../utils/kvStoreUtil'
// Create KV store
const kvStore = new KvStoreModel()
kvStore.createKvStore(context, callback)
// Put data
kvStore.put(key, value)
// Get data
kvStore.get(key)
// Subscribe to changes
kvStore.subscribeDataChange(callback)- Tutorial - Detailed code explanations and architecture deep-dives
- Changelog - Version history and release notes
- Oniro Project Documentation - Oniro project resources
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Please ensure your code follows the project's coding standards and includes appropriate tests.
See CHANGELOG.md for a detailed version history.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Author: imansmallapple
- Repository: https://github.com/eclipse-oniro4openharmony/app-SuperDeviceDemo
- Issues: https://github.com/eclipse-oniro4openharmony/app-SuperDeviceDemo/issues
