<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: 魔眼天王</title>
    <description>The latest articles on DEV Community by 魔眼天王 (@moyantianwang).</description>
    <link>https://dev.to/moyantianwang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3235566%2Ff9b9313b-aba0-4305-92c9-f67066568b56.jpg</url>
      <title>DEV Community: 魔眼天王</title>
      <link>https://dev.to/moyantianwang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/moyantianwang"/>
    <language>en</language>
    <item>
      <title>Basic Network Request Implementation Steps in HarmonyOS</title>
      <dc:creator>魔眼天王</dc:creator>
      <pubDate>Mon, 30 Jun 2025 07:08:28 +0000</pubDate>
      <link>https://dev.to/moyantianwang/basic-network-request-implementation-steps-in-harmonyos-g57</link>
      <guid>https://dev.to/moyantianwang/basic-network-request-implementation-steps-in-harmonyos-g57</guid>
      <description>&lt;h4&gt;
  
  
  I. Basic Configuration Preparation
&lt;/h4&gt;

&lt;p&gt;Before initiating network requests, complete two core configurations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;​Permission Declaration​
Add network access permissions in module.json5:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   "requestPermissions": [  
     {  
       "name": "ohos.permission.INTERNET"  
     }  
   ]  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For HTTP requests, add "cleartextTraffic": true&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;​Module Import​
Import the network module in JS/TS files:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   import http from '@ohos.net.http';  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  II. GET Request Implementation Steps
&lt;/h4&gt;

&lt;p&gt;Sample scenario: Fetching news list data&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;​Create Request Object​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   let httpRequest = http.createHttp();  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Configure Request Parameters​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   const url = "https://api.example.com/news";  
   const options = {  
     method: http.RequestMethod.GET,  
     header: {  
       "Content-Type": "application/json",  
       "Authorization": "Bearer your_token" // Optional auth header  
     },  
     connectTimeout: 10000, // 10s timeout  
     readTimeout: 15000  
   };  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Send Request &amp;amp; Handle Response​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   try {  
     const response = await httpRequest.request(url, options);  
     if (response.responseCode === http.ResponseCode.OK) {  
       const newsData = JSON.parse(response.result as string);  
       console.log("News title:", newsData.title);  
     } else {  
       console.error("Server error code:", response.responseCode);  
     }  
   } catch (err) {  
     console.error("Request error:", (err as BusinessError).message);  
   } finally {  
     httpRequest.destroy(); // Must release resources  
   }  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  III. POST Request Implementation Steps
&lt;/h4&gt;

&lt;p&gt;Sample scenario: Submitting user comments&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;​Construct Request Body​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   const postData = {  
     articleId: 123,  
     content: "HarmonyOS development is efficient!",  
     userId: "user_001"  
   };  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Send POST Request​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   try {  
     const response = await httpRequest.request("https://api.example.com/comment", {  
       method: http.RequestMethod.POST,  
       header: { "Content-Type": "application/json" },  
       extraData: JSON.stringify(postData) // Pass JSON data  
     });  
     if (response.responseCode === 201) { // 201 Created  
       showToast("Comment submitted successfully");  
     }  
   } catch (err) {  
     showError("Network error, please retry");  
   }  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​&lt;/p&gt;

&lt;h4&gt;
  
  
  IV. Key Configuration Details
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Configuration Item&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Required&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;method&lt;/td&gt;
&lt;td&gt;HTTP method (GET/POST, etc.)&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;header&lt;/td&gt;
&lt;td&gt;Headers (auth, content type)&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;extraData&lt;/td&gt;
&lt;td&gt;POST request body&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;timeout&lt;/td&gt;
&lt;td&gt;Timeout (milliseconds)&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;responseType&lt;/td&gt;
&lt;td&gt;Response type (JSON/TEXT)&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;​*&lt;em&gt;​&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  V. Less Common Requests
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;​File Upload​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   const file = await fileio.readFile("/data/photo.jpg");  
   const uploadResponse = await httpRequest.request(  
     "https://api.example.com/upload",  
     {  
       method: http.RequestMethod.POST,  
       header: { "Content-Type": "multipart/form-data" },  
       extraData: file  
     }  
   );  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Streaming Response Handling​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   const stream = await httpRequest.request(  
     "https://example.com/large-video.mp4",  
     { responseType: http.HttpDataType.STREAM }  
   );  
   const buffer = await stream.readBuffer();  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​&lt;/p&gt;

&lt;h4&gt;
  
  
  VI. Error Handling
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {  
  // Request code...  
} catch (err) {  
  if ((err as BusinessError).code === 'ECONNABORTED') {  
    showError("Request timeout, check network");  
  } else if (err instanceof NetworkError) {  
    showError("Network connection failed");  
  } else {  
    showError("Server internal error");  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​*&lt;em&gt;​&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  VII. Performance Optimization
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;​Connection Reuse​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   // Create singleton during app initialization  
   const globalHttp = http.createHttp();  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Cache Strategy​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   const options = {  
     usingCache: true, // Enable cache  
     cacheMode: http.CacheMode.REQUEST_NETWORK // Prefer network data  
   };  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Concurrency Control​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   const maxConcurrent = 5; // Max concurrent requests  
   let currentCount = 0;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​&lt;/p&gt;

&lt;h4&gt;
  
  
  VIII. Debugging
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;​Packet Sniffing​
Configure proxy with Charles/Fiddler:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   import network from '@ohos.net.network';  
   network.setProxy("192.168.1.100", 8888);  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Log Output​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   import log from '@ohos.hilog';  
   log.info("NET", "Request URL: %{public}s", url);  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​&lt;/p&gt;

&lt;h4&gt;
  
  
  IX. Full Code Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Entry  
@Component  
struct NewsPage {  
  private newsList: Array&amp;lt;{ title: string }&amp;gt; = [];  

  aboutToAppear() {  
    this.fetchNews();  
  }  

  async fetchNews() {  
    try {  
      let httpRequest = http.createHttp();  
      const response = await httpRequest.request(  
        "https://api.example.com/news",  
        {  
          method: http.RequestMethod.GET,  
          header: { "Content-Type": "application/json" }  
        }  
      );  
      if (response.responseCode === 200) {  
        this.newsList = JSON.parse(response.result as string);  
      }  
    } finally {  
      httpRequest?.destroy();  
    }  
  }  

  build() {  
    Column() {  
      ForEach(this.newsList, (item) =&amp;gt; {  
        Text(item.title)  
          .fontSize(20)  
          .padding(16)  
      })  
    }  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>harmonyos</category>
    </item>
    <item>
      <title>Core Implementation Principles and Development Steps of HarmonyOS "Tap-to-Share" Feature</title>
      <dc:creator>魔眼天王</dc:creator>
      <pubDate>Fri, 27 Jun 2025 09:44:56 +0000</pubDate>
      <link>https://dev.to/moyantianwang/core-implementation-principles-and-development-steps-of-harmonyos-tap-to-share-feature-2h0d</link>
      <guid>https://dev.to/moyantianwang/core-implementation-principles-and-development-steps-of-harmonyos-tap-to-share-feature-2h0d</guid>
      <description>&lt;p&gt;​*&lt;em&gt;​&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  I. Technical Principles
&lt;/h2&gt;

&lt;p&gt;HarmonyOS "Tap-to-Share" leverages ​NFC + Distributed Soft Bus​ dual engines, with core architecture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Physical Layer (NFC Chip) ↔ Protocol Layer (HMS Core) ↔ Distributed Layer (Soft Bus)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​NFC Trigger: Integrated NFC sensing area on device top, communicating via ISO/IEC 14443 protocol within 10cm range&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Distributed Communication: Establishes secure channels through RPC framework with AES-256-CBC end-to-end encryption&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​ArkUI Rendering: Dynamically generates share cards using declarative UI framework for cross-device synchronization&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​*&lt;em&gt;​&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  II. Development Implementation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Environment Configuration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Check device compatibility  
if (canIUse('SystemCapability.Collaboration.HarmonyShare')) {  
  // Initialize distributed capabilities  
  await distributedData.init();  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Event Registration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Register tap-to-share listener  
harmonyShare.on('knockShare', (event) =&amp;gt; {  
  const target = event.sharableTarget;  
  handleShare(target);  
});  

// Remove listener on page unload  
onPageHide(() =&amp;gt; {  
  harmonyShare.off('knockShare');  
});  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Data Construction &amp;amp; Trigger
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Build share data object  
const shareData = new ShareData({  
  type: ShareType.LINK,  
  content: 'https://example.com',  
  thumbnail: fileUri.getUriFromPath('/images/share.png'),  
  title: 'Project Proposal',  
  description: '2025 Technical Roadmap'  
});  

// Initiate tap-to-share  
const targetDevice = await findNearbyDevice();  
targetDevice.share(shareData);  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Result Handling
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Monitor transfer status  
distributedData.on('transferStatus', (status) =&amp;gt; {  
  if (status === 'SUCCESS') {  
    showToast('Transfer completed');  
  } else {  
    showError('Transfer failed');  
  }  
});  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​*&lt;em&gt;​&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  III. Technical Advantages
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;​Millisecond Device Discovery​&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Utilizes NFC ATR protocol for device fingerprinting (&amp;lt;80ms response)&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;​Secure Transmission​&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Device fingerprint mutual authentication (TEE-based)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fragmented encryption (128B chunks with dynamic key rotation)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;​Smart Context Recognition​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   graph LR  
   A[Tap] --&amp;gt; B{Content Identification}  
   B --&amp;gt;|Image| C[Launch Gallery]  
   B --&amp;gt;|Text| D[Launch Notes]  
   B --&amp;gt;|File| E[Launch File Manager]  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​*&lt;em&gt;​&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  IV. Performance Metrics
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Transfer Speed&lt;/th&gt;
&lt;th&gt;Success Rate&lt;/th&gt;
&lt;th&gt;Latency&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1MB Image&lt;/td&gt;
&lt;td&gt;24 MB/s&lt;/td&gt;
&lt;td&gt;99.8%&lt;/td&gt;
&lt;td&gt;120ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10MB Document&lt;/td&gt;
&lt;td&gt;18 MB/s&lt;/td&gt;
&lt;td&gt;99.5%&lt;/td&gt;
&lt;td&gt;150ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100MB Video&lt;/td&gt;
&lt;td&gt;12 MB/s&lt;/td&gt;
&lt;td&gt;98.2%&lt;/td&gt;
&lt;td&gt;210ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;​*&lt;em&gt;​&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  V. Use Cases
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;​Cross-Device Sharing​&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Phone → Tablet: Design files with layer preservation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PC → Phone: Meeting notes auto-sync to Notes app&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;​Smart Device Control​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   // Connect to smart lighting  
   const device = await findDeviceByType('LIGHT');  
   await device.executeCommand('setBrightness', 80);  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Contactless Payments​&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Phone tap POS for payments (no app launch)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Public transit card tap for instant recharge&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​*&lt;em&gt;​&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  VI. Comparative Advantages
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;Traditional NFC&lt;/th&gt;
&lt;th&gt;HarmonyOS Tap-to-Share&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Interaction&lt;/td&gt;
&lt;td&gt;Requires dedicated APP&lt;/td&gt;
&lt;td&gt;System-native support&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Efficiency&lt;/td&gt;
&lt;td&gt;Protocol-dependent&lt;/td&gt;
&lt;td&gt;Direct device connection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scalability&lt;/td&gt;
&lt;td&gt;Single-function&lt;/td&gt;
&lt;td&gt;Dynamic capability expansion&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Security&lt;/td&gt;
&lt;td&gt;Device-level auth&lt;/td&gt;
&lt;td&gt;App+User dual-factor&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;​*&lt;em&gt;​&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  VII. Implementation Notes
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;​Permission Management​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   // Request necessary permissions  
   requestPermissions(['ohos.permission.NFC', 'ohos.permission.INTERNET']);  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Error Handling​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   try {  
     await device.connect();  
   } catch (e) {  
     if (e.code === 'DEVICE_BUSY') {  
       showToast('Device busy, retry');  
     }  
   }  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Optimization Tips​&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use shareData.compress() for content reduction&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Chunk large files (≤500KB per fragment)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>harmonyos</category>
    </item>
    <item>
      <title>Core Database Operation Solutions in HarmonyOS</title>
      <dc:creator>魔眼天王</dc:creator>
      <pubDate>Fri, 27 Jun 2025 09:31:26 +0000</pubDate>
      <link>https://dev.to/moyantianwang/core-database-operation-solutions-in-harmonyos-2hn8</link>
      <guid>https://dev.to/moyantianwang/core-database-operation-solutions-in-harmonyos-2hn8</guid>
      <description>&lt;h4&gt;
  
  
  I. Native API Deep Dive
&lt;/h4&gt;

&lt;p&gt;HarmonyOS provides two native database solutions: ​Relational Database (RDB)​​ and ​Object-Relational Mapping (ORM)​, both built on SQLite.&lt;/p&gt;

&lt;h5&gt;
  
  
  1. Relational Database (RDB)
&lt;/h5&gt;

&lt;p&gt;​Core API Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Database Initialization (TypeScript)  
import relationalStore from '@ohos.data.relationalStore';  

const config = {  
  name: 'user.db',  
  securityLevel: relationalStore.SecurityLevel.S1  
};  

async function initDB() {  
  const store = await relationalStore.getRdbStore(config);  
  await store.executeSql(  
    'CREATE TABLE IF NOT EXISTS user (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)'  
  );  
}  

// Batch Insert with Transactions  
async function batchInsert(users: string[]) {  
  const store = await relationalStore.getRdbStore(config);  
  await store.beginTransaction();  
  try {  
    users.forEach(name =&amp;gt; {  
      store.insert('user', { name });  
    });  
    await store.commit();  
  } catch (e) {  
    await store.rollback();  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;​Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Direct SQL control for complex queries (e.g., multi-table joins)&lt;/li&gt;
&lt;li&gt;Full ACID transaction support&lt;/li&gt;
&lt;li&gt;Distributed sync capability (API 18+)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;​Limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Manual SQL injection prevention&lt;/li&gt;
&lt;li&gt;Strict single-writer/multi-reader rules for multi-threading&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h5&gt;
  
  
  2. Object-Relational Mapping (ORM)
&lt;/h5&gt;

&lt;p&gt;​Code Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Entity Definition  
@Entity(tableName = 'product')  
class Product extends OrmObject {  
  @PrimaryKey(autoGenerate = true)  
  private id: number;  
  @Column(String) name: string;  
}  

// Database Operations  
const ormContext = ormCreateDb();  
const product = new Product();  
product.name = 'Smart Watch';  
await ormContext.insert(product);  
const results = await ormContext.query(  
  ormContext.where(Product).equalTo('name', 'Smart Watch')  
);  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;50% less boilerplate code (no manual SQL)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Compile-time type safety&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Automatic object serialization&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​*&lt;em&gt;​&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  II. Third-Party Libraries Comparison
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. ObjectBox (Community Recommendation)
&lt;/h5&gt;

&lt;p&gt;​Integration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// package.json  
"dependencies": {  
  "com.objectbox.objectbox": "1.6.0"  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Code Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Entity Definition  
@Entity  
class User {  
  @Id(autoincrement = true)  
  id: number;  
  name: string;  
}  

// Operations  
const boxStore = MyObjectBox.builder().build();  
const userBox = boxStore.boxFor(User.class);  
userBox.put(new User("Zhang San"));  
const users = userBox.query().build().find();  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Performance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Insertion: 1,800 entries/sec vs. Native API's 1,200&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Query Latency: 18ms vs. 25ms&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Use Cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;High-frequency IoT logging&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Complex object relationships&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  2. HSQLDB (Lightweight Option)
&lt;/h5&gt;

&lt;p&gt;​Features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Pure Java implementation (no native dependencies)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In-memory database support&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { HSQLDatabase } from '@ohos.hsqldb';  
const db = new HSQLDatabase();  
await db.connect('jdbc:hsqldb:mem:test');  
await db.execute('CREATE TABLE session (id INT PRIMARY KEY)');  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Limited transaction support (row-level locking only)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No distributed deployment&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​*&lt;em&gt;​&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  III. Performance &amp;amp; Scenario Comparison
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;Native API&lt;/th&gt;
&lt;th&gt;ORM Framework&lt;/th&gt;
&lt;th&gt;ObjectBox&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Development&lt;/td&gt;
&lt;td&gt;★★☆ (SQL required)&lt;/td&gt;
&lt;td&gt;★★★★ (Type-safe)&lt;/td&gt;
&lt;td&gt;★★★☆&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Speed&lt;/td&gt;
&lt;td&gt;★★★★ (Direct)&lt;/td&gt;
&lt;td&gt;★★★ (ORM overhead)&lt;/td&gt;
&lt;td&gt;★★★★☆&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Learning&lt;/td&gt;
&lt;td&gt;★★★ (SQL needed)&lt;/td&gt;
&lt;td&gt;★★☆ (Annotations)&lt;/td&gt;
&lt;td&gt;★★★☆&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Complex Query&lt;/td&gt;
&lt;td&gt;★★★★ (JOIN support)&lt;/td&gt;
&lt;td&gt;★★☆ (Generator)&lt;/td&gt;
&lt;td&gt;★★★☆&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Distributed&lt;/td&gt;
&lt;td&gt;★★★★ (API 18+)&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;​*&lt;em&gt;​&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  IV. Selection Guide
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;​Native API:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ideal for complex data models needing distributed sync&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use @Transaction for batch operations&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;​ORM Framework:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Top choice for small/medium projects (TypeScript decorators)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Note: Manual Date type conversions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;​Third-Party:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​ObjectBox: IoT local storage&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​HSQLDB: Memory-light apps&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Optimizations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use executeBatch() instead of loops (+3x throughput)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Specify columns in queries to avoid full scans&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enable WAL mode (PRAGMA journal_mode=WAL) for concurrency&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>harmonyos</category>
    </item>
    <item>
      <title>Core Feature Evolution of HarmonyOS API Versions (12-18)</title>
      <dc:creator>魔眼天王</dc:creator>
      <pubDate>Fri, 27 Jun 2025 08:29:08 +0000</pubDate>
      <link>https://dev.to/moyantianwang/core-feature-evolution-of-harmonyos-api-versions-12-18-18p1</link>
      <guid>https://dev.to/moyantianwang/core-feature-evolution-of-harmonyos-api-versions-12-18-18p1</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Feeling the rapid updates of HarmonyOS? Here's a comprehensive guide to key enhancements across API versions 12-18 to help you stay updated. Feedback is welcome for continuous improvement.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  I. Version Roadmap
&lt;/h2&gt;

&lt;p&gt;HarmonyOS achieved ​5 major version updates​ from October 2024 to June 2025, advancing API levels from 12 to 18:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HarmonyOS 5.0.0 (API 12) → 5.0.1 (13) → 5.0.2 (14) → 5.0.3 (15) → 5.0.4 (16) → 5.1.0 (18)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  II. Key Features by API Version
&lt;/h2&gt;

&lt;h3&gt;
  
  
  API 12 (HarmonyOS 5.0.0)
&lt;/h3&gt;

&lt;p&gt;​Core Breakthroughs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​ArkUI 3.0: Full transition to declarative framework with dynamic layout and reactive state management (e.g., Text().fontSize(20))&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Unified Data Model (UDMF)​: Cross-device data validation and synchronization&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Hardware TEE: Enhanced encryption and dynamic permission management&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Typical Use Cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Multi-device collaboration (e.g., real-time document sharing between phone/tablet)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Privacy-compliant financial apps&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*&lt;/p&gt;

&lt;h3&gt;
  
  
  API 13 (HarmonyOS 5.0.1)
&lt;/h3&gt;

&lt;p&gt;​Core Breakthroughs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​C API Extensions: 200+ low-level interfaces for UI property control (e.g., window transparency)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Media Enhancements: HE-AAC audio codec, lyric highlight in AVSession Kit&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Atomic File Operations: Ensuring large file transfer integrity&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Developer Tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DevEco Studio 5.0.1 supports direct HAP package upload&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  API 14 (HarmonyOS 5.0.2)
&lt;/h3&gt;

&lt;p&gt;​Core Breakthroughs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;​2-in-1 Device Support:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Window size memory for foldable devices&lt;/li&gt;
&lt;li&gt;Font scaling via ID mapping&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;​ArkUI Improvements: Custom navigation transitions, standalone text selection menu&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;​Memory Leak Detection: Integrated with HiLog (40% faster diagnosis)&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  API 15 (HarmonyOS 5.0.3)
&lt;/h3&gt;

&lt;p&gt;​Core Breakthroughs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Smart Data Platform: UDMF AI feature extraction for IoT&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Game Controller Support: Axis event handling&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​PAC Proxy: Enterprise network access solution&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Security: Granular input method permissions&lt;/p&gt;

&lt;h3&gt;
  
  
  API 16 (HarmonyOS 5.0.4)
&lt;/h3&gt;

&lt;p&gt;​Core Breakthroughs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Reading Ecosystem: EPUB3.0/DOCX support in Reader Kit&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​GPU Passthrough: 120Hz rendering via ArkGraphics 2D&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Bluetooth MAC Persistence: 30-day file recovery&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Performance: 35% lower screen recording memory usage&lt;/p&gt;

&lt;h3&gt;
  
  
  API 17 (HarmonyOS 5.0.5)
&lt;/h3&gt;

&lt;p&gt;​Core Breakthroughs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;​Window Control:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PiP window state persistence&lt;/li&gt;
&lt;li&gt;Dynamic shadow blur radius&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;​AR Engine: Depth estimation API (&amp;lt;2cm accuracy)&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;​Recycle Bin: 30-day file recovery&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;​Multi-Device: &amp;lt;200ms task scheduling latency&lt;/p&gt;

&lt;h3&gt;
  
  
  API 18 (HarmonyOS 5.1.0)
&lt;/h3&gt;

&lt;p&gt;​Core Breakthroughs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;​Distributed Security:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Group asset access control&lt;/li&gt;
&lt;li&gt;Virtual Bluetooth MAC addresses&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;​ArkUI Innovations: ArcList, crown rotation events&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;​Media Codec: MPEG2/H.263 support&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;​Ecosystem: 300,000+ Android app compatibility&lt;/p&gt;

&lt;h2&gt;
  
  
  III. Version Evolution Trends
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;API 12-14&lt;/th&gt;
&lt;th&gt;API 15-17&lt;/th&gt;
&lt;th&gt;API 18&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;​Architecture​&lt;/td&gt;
&lt;td&gt;Distributed framework foundation&lt;/td&gt;
&lt;td&gt;Multi-device synergy&lt;/td&gt;
&lt;td&gt;Security + AI integration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;​Dev Experience​&lt;/td&gt;
&lt;td&gt;Declarative UI adoption&lt;/td&gt;
&lt;td&gt;C API openness + tooling&lt;/td&gt;
&lt;td&gt;Native smart components&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;​Use Cases​&lt;/td&gt;
&lt;td&gt;Basic IoT apps&lt;/td&gt;
&lt;td&gt;Automotive/reading/gaming&lt;/td&gt;
&lt;td&gt;Cross-scenario interaction&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  IV. Performance Optimization
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Area&lt;/th&gt;
&lt;th&gt;Technique&lt;/th&gt;
&lt;th&gt;Improvement&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cold Startup&lt;/td&gt;
&lt;td&gt;Critical module preloading&lt;/td&gt;
&lt;td&gt;38% faster first frame&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Animation&lt;/td&gt;
&lt;td&gt;RenderGroup optimization&lt;/td&gt;
&lt;td&gt;65% fewer frame drops&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memory&lt;/td&gt;
&lt;td&gt;LRU caching strategy&lt;/td&gt;
&lt;td&gt;22% lower peak usage&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  V. Multi-Device Synergy
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Distributed Soft Bus: 10 devices @ 5Gbps&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Task Migration: AI-predicted node switching (50ms latency)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  VI. Security Enhancements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Data Sandbox: Component-level isolation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Anti-Fraud: 98.7% accuracy with IME Kit&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  VII. Developer Toolchain
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;graph LR  
A[DevEco Studio 5.1] --&amp;gt; B[ArkCompiler 3.0]  
A --&amp;gt; C[HiLog 2.0]  
A --&amp;gt; D[Performance Suite]  
B --&amp;gt; E[40% faster build]  
C --&amp;gt; F[Log filtering]  
D --&amp;gt; G[1ms frame monitoring]  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  VIII. Ecosystem Growth
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Device Support: 13 form factors (e.g., smart cockpits, AR glasses)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Developer Resources: 200+ test templates, 72-hour bug fixes&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>harmonyos</category>
    </item>
    <item>
      <title>HarmonyOS Tabs Style Configuration Guide</title>
      <dc:creator>魔眼天王</dc:creator>
      <pubDate>Thu, 26 Jun 2025 10:29:25 +0000</pubDate>
      <link>https://dev.to/moyantianwang/harmonyos-tabs-style-configuration-guide-g6p</link>
      <guid>https://dev.to/moyantianwang/harmonyos-tabs-style-configuration-guide-g6p</guid>
      <description>&lt;h2&gt;
  
  
  I. Core Style System
&lt;/h2&gt;

&lt;p&gt;HarmonyOS Tabs component provides a three-tier style control system to meet diverse customization needs:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Basic Style Configuration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tabs({  
  tabBar: {  
    indicator: {  
      color: Color.Red,    // Underline color  
      height: 4,           // Underline height  
      width: 80,           // Underline width  
      borderRadius: 3      // Border radius  
    },  
    labelStyle: {  
      font: { size: 18, weight: FontWeight.Bold },  
      selectedColor: Color.Blue,  // Selected text color  
      unselectedColor: Color.Gray // Unselected text color  
    }  
  }  
})  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Dynamic color binding (responsive theme switching)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Automatic underline centering&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Smooth font transition animation (300ms easing)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Use Cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Basic navigation (Home/Category/Profile)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Quick standard style implementation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Navigation Bar Positioning
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Property&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;th&gt;Effect&lt;/th&gt;
&lt;th&gt;Typical Scene&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;barPosition&lt;/td&gt;
&lt;td&gt;Start/End&lt;/td&gt;
&lt;td&gt;Top/Bottom navigation&lt;/td&gt;
&lt;td&gt;Main app navigation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;vertical&lt;/td&gt;
&lt;td&gt;true/false&lt;/td&gt;
&lt;td&gt;Vertical layout&lt;/td&gt;
&lt;td&gt;Tablet sidebar&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tabs({  
  barPosition: BarPosition.End,  
  vertical: true,  
  barWidth: 80,    // Fixed sidebar width  
  barHeight: 200   // Sidebar height  
})  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  II. Advanced Style Implementations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Custom Navigation Bar (Text + Icon)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Builder  
tabBarBuilder(index: number, title: string) {  
  Column() {  
    Image($r(`app.media.icon_${index}`))  
      .width(24)  
      .height(24)  
      .objectFit(ImageFit.Cover)  

    Text(title)  
      .fontSize(16)  
      .fontColor(index === currentIndex ? Color.Red : Color.Gray)  
  }  
}  

Tabs() {  
  TabContent() {  
    Text("Home Content")  
  }.tabBar(this.tabBarBuilder(0, "Home"))  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Icon-text combination support&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Visual state indication&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Badge integration&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Performance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Memory increase: 15-20MB&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rendering overhead: +5-8ms/frame&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Dynamic Gradient Effect
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tabs().onGestureSwipe((offset) =&amp;gt; {  
  const ratio = offset / this.tabsWidth  
  this.indicatorWidth = 80 + ratio * 40  // Dynamic width  
  this.underlineColor = Color.interpolate(  
    [Color.Red, Color.Blue],  
    ratio  
  )  
})  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Effects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Width transition with swipe&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Smooth color interpolation (HSV/RGB)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enhanced inertia scrolling&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  III. Multi-Device Adaptation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Device-Specific Configuration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@State isTablet: boolean = deviceType === DeviceType.TABLET  

Tabs({  
  barPosition: this.isTablet ? BarPosition.Start : BarPosition.End,  
  vertical: this.isTablet,  
  barMode: this.isTablet ? BarMode.Scrollable : BarMode.Fixed  
})  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Screen Adaptation Matrix
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Device&lt;/th&gt;
&lt;th&gt;Position&lt;/th&gt;
&lt;th&gt;Resolution&lt;/th&gt;
&lt;th&gt;Special Handling&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Phone Portrait&lt;/td&gt;
&lt;td&gt;Bottom&lt;/td&gt;
&lt;td&gt;800x1200px&lt;/td&gt;
&lt;td&gt;4px underline height&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Phone Landscape&lt;/td&gt;
&lt;td&gt;Top&lt;/td&gt;
&lt;td&gt;1200x800px&lt;/td&gt;
&lt;td&gt;30% padding increase&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tablet Portrait&lt;/td&gt;
&lt;td&gt;Left&lt;/td&gt;
&lt;td&gt;1600x2560px&lt;/td&gt;
&lt;td&gt;120px sidebar width&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Smartwatch&lt;/td&gt;
&lt;td&gt;Circular&lt;/td&gt;
&lt;td&gt;396x396px&lt;/td&gt;
&lt;td&gt;SVG icons + dynamic scaling&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  IV. Performance Optimization
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Rendering Benchmarks
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Style Complexity&lt;/th&gt;
&lt;th&gt;First Frame (ms)&lt;/th&gt;
&lt;th&gt;Memory (MB)&lt;/th&gt;
&lt;th&gt;FPS While Scrolling&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Text Only&lt;/td&gt;
&lt;td&gt;120&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;60&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Text + Image&lt;/td&gt;
&lt;td&gt;180&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;55&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dynamic Gradient&lt;/td&gt;
&lt;td&gt;220&lt;/td&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;td&gt;48&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  2. Optimization Strategies
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Virtualized Rendering: Only render visible Tabs (50% memory reduction)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Style Caching: Pre-generate common style objects (+30% rendering speed)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Animation Optimization: CSS animations over JS (+20% frame rate)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  V. Implementation Patterns
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Bottom Navigation Pattern
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tabs({  
  barPosition: BarPosition.End,  
  indicator: {  
    height: 4,  
    color: Color.Blue  
  }  
}) {  
  TabContent() { Text("Home") }.tabBar("Home")  
  TabContent() { Text("Profile") }.tabBar("Profile")  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Scrollable Tab Pattern
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tabs({  
  barMode: BarMode.Scrollable,  
  barWidth: "100%"  
}) {  
  // Multiple TabContent components  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>harmonyos</category>
    </item>
    <item>
      <title>Deep Dive into HarmonyOS 3D Complex Animation Technology</title>
      <dc:creator>魔眼天王</dc:creator>
      <pubDate>Thu, 26 Jun 2025 10:16:06 +0000</pubDate>
      <link>https://dev.to/moyantianwang/deep-dive-into-harmonyos-3d-complex-animation-technology-5f1j</link>
      <guid>https://dev.to/moyantianwang/deep-dive-into-harmonyos-3d-complex-animation-technology-5f1j</guid>
      <description>&lt;h2&gt;
  
  
  I. Core Technical Architecture
&lt;/h2&gt;

&lt;p&gt;HarmonyOS implements 3D animation capabilities through the integration of ArkUI 3D Graphics Engine and Distributed Rendering Framework, structured as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application Layer (ArkTS Animation APIs) ↔ Middleware Layer (SceneGraph Engine) ↔ Hardware Layer (GPU/Vulkan Acceleration)  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​SceneGraph Engine: Manages 3D scene primitives and animation state machines&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​GPU Acceleration Pipeline: Supports OpenGL ES 3.2/Vulkan 1.3 graphics APIs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Physics Simulation Module: Integrates Bullet Physics Engine for rigid/flexible body dynamics&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  II. Main 3D Animation Implementation Schemes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Property Animation (3D Transform)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 3D rotation transformation implementation  
@Entry  
@Component  
struct Rotate3DExample {  
  private angle: number = 0  

  build() {  
    Image($r('app.media.logo'))  
      .transform({  
        rotateY: this.angle.animateTo(  
          { duration: 2000, curve: Curve.Spring },  
          360  
        )  
      })  
      .onClick(() =&amp;gt; this.angle += 90)  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Smooth transitions through property binding&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports basic transforms: rotateX/Y/Z, scale3d, translate3d&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Automatic matrix operations and GPU upload handling&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Use Cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Card flip/rotation interactions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Basic 3D model showcase&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simple UI animations&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Cannot handle complex skeletal animations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Limited synchronization control for multiple animations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Memory usage grows linearly with object count&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Skeletal Animation System
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Skeletal animation loading example  
class SkeletonAnimator {  
  private skeleton: SkeletonModel = loadSkeleton('avatar.skel')  

  playIdleAnimation() {  
    const anim = new AnimationClip('idle', 1.2)  
    anim.addKeyframe('spine', 0, Quaternion.createEuler(0, 0, 0))  
    anim.addKeyframe('spine', 0.6, Quaternion.createEuler(0, 45, 0))  
    this.skeleton.play(anim)  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Technical Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Hierarchical bone binding (up to 64-level parent-child relationships)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Skin weight editor support&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Animation blending and state machine control&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Performance Metrics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Single skeleton: 2ms/frame (CPU), 1.5ms/frame (GPU)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;50 skeletons: 18ms/frame (CPU), 12ms/frame (GPU)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Particle Effect System
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Particle system configuration  
const particleSystem = new ParticleSystem({  
  texture: 'fire.png',  
  maxParticles: 1000,  
  emissionRate: 50,  
  velocity: Vector3(0, 5, 0),  
  gravity: Vector3(0, -9.8, 0),  
  lifetime: 2.5  
})  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Core Capabilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;GPU Instancing rendering support&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configurable force fields (gravity/vortex/custom shaders)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;AABB-based collision detection&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Typical Applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Magical effects/explosions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Environmental systems (rain/snow/smoke)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fluid simulation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;High computational complexity for complex interactions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Exponential memory growth with particle count&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Limited physical accuracy&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  III. Performance Optimization Strategies
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Rendering Pipeline Optimization
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​LOD Technology: Auto-adjusts model precision based on viewing distance (up to 70% vertex reduction)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Occlusion Culling: Octree spatial partitioning for invisible geometry elimination&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Batch Processing: Static mesh merging reduces draw calls (40% overhead reduction)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Animation Resource Management
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Strategy&lt;/th&gt;
&lt;th&gt;Implementation&lt;/th&gt;
&lt;th&gt;Effect&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Animation Compression&lt;/td&gt;
&lt;td&gt;ETC2 textures + keyframe reduction&lt;/td&gt;
&lt;td&gt;50% model size reduction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Frame Rate Adaptation&lt;/td&gt;
&lt;td&gt;Dynamic speed adjustment based on device&lt;/td&gt;
&lt;td&gt;30FPS stability on low-end devices&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memory Pooling&lt;/td&gt;
&lt;td&gt;Pre-loading common animations&lt;/td&gt;
&lt;td&gt;70% load latency reduction&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  3. Distributed Rendering
&lt;/h3&gt;

&lt;p&gt;Cross-device collaborative rendering architecture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mobile (Primary) ↔ Tablet (Geometry Processing) ↔ Smart Screen (Post-processing)  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Supports 1080P@60FPS real-time rendering&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;3x performance boost through multi-device compute aggregation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamic workload balancing algorithm&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  IV. Practical Implementations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. AR Product Showcase
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 3D model loading and interaction  
@Entry  
@Component  
struct ARProductDemo {  
  private model: Model3D = loadModel('product.obj')  

  build() {  
    ARView()  
      .loadModel(this.model)  
      .onPinch((e: PinchEvent) =&amp;gt; {  
        this.model.scale = e.scale  
      })  
      .onRotate((e: RotateEvent) =&amp;gt; {  
        this.model.rotateY(e.angle)  
      })  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Performance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Triangle count: 350,000&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Memory peak: 1.2GB&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Frame rate: 45FPS in AR mode&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Industrial Simulation System
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Mechanical Arm Simulation: Rigid body dynamics for precise trajectory calculation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Fluid Dynamics: SPH algorithm for real-time liquid simulation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Collision Detection: GJK algorithm for complex shape responses&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  V. Comparative Analysis
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;Property Animation&lt;/th&gt;
&lt;th&gt;Skeletal Animation&lt;/th&gt;
&lt;th&gt;Particle System&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;​Complexity​&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;​Performance Cost​&lt;/td&gt;
&lt;td&gt;1-5ms/frame&lt;/td&gt;
&lt;td&gt;10-50ms/frame&lt;/td&gt;
&lt;td&gt;50-200ms/frame&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;​Visual Richness​&lt;/td&gt;
&lt;td&gt;Basic transforms&lt;/td&gt;
&lt;td&gt;Articulated movements&lt;/td&gt;
&lt;td&gt;Complex effects&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;​Development Cost​&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Moderate&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>harmonyos</category>
    </item>
    <item>
      <title>Multi-Data Source Component Reuse Solutions in HarmonyOS Development</title>
      <dc:creator>魔眼天王</dc:creator>
      <pubDate>Thu, 26 Jun 2025 09:57:28 +0000</pubDate>
      <link>https://dev.to/moyantianwang/multi-data-source-component-reuse-solutions-in-harmonyos-development-34ci</link>
      <guid>https://dev.to/moyantianwang/multi-data-source-component-reuse-solutions-in-harmonyos-development-34ci</guid>
      <description>&lt;h2&gt;
  
  
  I. Key Challenges
&lt;/h2&gt;

&lt;p&gt;In HarmonyOS development, component reuse faces three main challenges with multi-data source adaptation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;​Heterogeneous Data Structures: Differences in JSON structures returned by various data sources (e.g., e-commerce product data vs. news feed data)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Update Frequency Discrepancies: Conflicting update rhythms between real-time sensor data (100ms-level) and configuration data (hourly-level)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​State Management Complexity: State synchronization issues during concurrent updates from multiple data sources&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  II. Main Solution Comparison
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Multi-Source Adapter Pattern
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Multi-Source Adapter Implementation
class MultiSourceAdapter {
  private sources: DataSource[] = [];

  register(source: DataSource) {
    this.sources.push(source);
  }

  async fetchData() {
    return Promise.all(
      this.sources.map(s =&amp;gt; s.query())
    ).then(results =&amp;gt; this.merge(results));
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Unified data interface (standardized output)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamic data source loading (hot-swappable)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Complete decoupling of business logic from data retrieval&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Disadvantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Requires asynchronous merge logic handling&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Additional type safety processing (generic constraints)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Linear memory growth with data source increase&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Use Cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Multi-API data aggregation (e.g., weather + PM2.5)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Third-party service integration (payment/map)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hybrid loading of local cache + cloud data&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. State Bus Architecture
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Global State Management
const eventBus = new EventBus();

// Data Source A Subscription
eventBus.on('data-update', (data: DataSourceA) =&amp;gt; {
  this.processData(data);
});

// Data Source B Update Trigger
fetchDataB().then(data =&amp;gt; {
  eventBus.emit('data-update', data);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Loose coupling communication&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multi-component collaborative response&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Native event priority support&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Disadvantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Complex event namespace management&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Debugging difficulties (event flow tracing)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Memory leak risks (improper listener cleanup)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Use Cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Cross-component state synchronization (theme switching)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Real-time messaging (chat notifications)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Complex business process orchestration&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Reactive Data Stream
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// RxJS Data Stream Merging
const data$ = merge(
  dataSourceA$.pipe(debounceTime(300)),
  dataSourceB$.pipe(throttleTime(1000))
).pipe(
  distinctUntilChanged(),
  catchError(handleError)
);

data$.subscribe(renderComponent);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Fine-grained data flow control (throttling/debouncing)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Complex operator chaining&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Automatic backpressure handling&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Disadvantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Steep learning curve&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Incomplete debugging tools&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Higher cold start latency&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;​Use Cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Real-time monitoring (stock/sensors)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Immediate user input response&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;High-frequency update scenarios&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  III. Performance Benchmark
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Solution&lt;/th&gt;
&lt;th&gt;Memory Usage (MB)&lt;/th&gt;
&lt;th&gt;Initial Load (ms)&lt;/th&gt;
&lt;th&gt;Update Latency (ms)&lt;/th&gt;
&lt;th&gt;Concurrency&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Adapter Pattern&lt;/td&gt;
&lt;td&gt;12.4&lt;/td&gt;
&lt;td&gt;85&lt;/td&gt;
&lt;td&gt;120&lt;/td&gt;
&lt;td&gt;5 sources&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;State Bus&lt;/td&gt;
&lt;td&gt;9.8&lt;/td&gt;
&lt;td&gt;140&lt;/td&gt;
&lt;td&gt;85&lt;/td&gt;
&lt;td&gt;10 sources&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reactive Streams&lt;/td&gt;
&lt;td&gt;15.2&lt;/td&gt;
&lt;td&gt;210&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;td&gt;20 sources&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  IV. Practical Implementations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Layered Architecture Design
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Multi-tier Data Flow Architecture
class DataService {
  private localSource = new LocalDataSource();
  private remoteSource = new RemoteDataSource();

  getData() {
    return this.remoteSource.fetch().pipe(
      catchError(() =&amp;gt; this.localSource.loadCache()),
      shareReplay(1)
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Intelligent Caching Strategy
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Cache Management Implementation
class DataCache {
  private cache = new Map&amp;lt;string, CachedItem&amp;gt;();

  set(key: string, data: any, ttl = 60000) {
    this.cache.set(key, {
      data,
      expire: Date.now() + ttl
    });
  }

  get(key: string) {
    const item = this.cache.get(key);
    return item?.expire &amp;gt; Date.now() ? item.data : null;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Fault Tolerance Mechanism
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Multi-Source Circuit Breaker
class FaultTolerantDataSource {
  private circuitBreaker = new CircuitBreaker();

  async fetchData() {
    return this.circuitBreaker.execute(() =&amp;gt; 
      this.dataSource.fetch()
    ).catch(fallbackToCache);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  V. Comparative Analysis
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. vs. Traditional Solutions
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;Adapter Pattern&lt;/th&gt;
&lt;th&gt;State Bus&lt;/th&gt;
&lt;th&gt;Reactive Streams&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;​Architecture​&lt;/td&gt;
&lt;td&gt;Layered&lt;/td&gt;
&lt;td&gt;Event-driven&lt;/td&gt;
&lt;td&gt;Reactive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;​Data Flow​&lt;/td&gt;
&lt;td&gt;Unidirectional&lt;/td&gt;
&lt;td&gt;Bidirectional&lt;/td&gt;
&lt;td&gt;Bidirectional&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;​State Management​&lt;/td&gt;
&lt;td&gt;Explicit&lt;/td&gt;
&lt;td&gt;Implicit&lt;/td&gt;
&lt;td&gt;Auto-managed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;​Debugging​&lt;/td&gt;
&lt;td&gt;Moderate&lt;/td&gt;
&lt;td&gt;Challenging&lt;/td&gt;
&lt;td&gt;Advanced&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;​Performance​&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Moderate&lt;/td&gt;
&lt;td&gt;Optimal&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  2. Implementation Guidelines
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;​Adapter Pattern:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use for heterogeneous data normalization&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implement type guards for data validation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apply memoization for frequent queries&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;​State Bus:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Adopt event semantic versioning&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implement dead-letter queues for failed events&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use namespaced topics for large-scale systems&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;​Reactive Streams:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Design observable hierarchies&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implement backpressure strategies&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Utilize schedulers for task prioritization&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  VI. Best Practices
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;​Data Source Prioritization:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   const prioritySources = [
     highPriorityDataSource,
     mediumPriorityDataSource,
     lowPriorityDataSource
   ];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Hybrid Loading Strategies:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   const loadData = async () =&amp;gt; {
     const [cached, remote] = await Promise.all([
       loadFromCache(),
       fetchRemoteData()
     ]);
     return mergeData(cached, remote);
   };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Error Recovery Patterns:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   retryPolicy.configure({
     maxRetries: 3,
     backoff: {
       type: 'exponential',
       delay: 1000
     }
   });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>harmonyos</category>
    </item>
    <item>
      <title>HMRouter Deep Dive</title>
      <dc:creator>魔眼天王</dc:creator>
      <pubDate>Wed, 25 Jun 2025 11:58:55 +0000</pubDate>
      <link>https://dev.to/moyantianwang/hmrouter-deep-dive-4d4c</link>
      <guid>https://dev.to/moyantianwang/hmrouter-deep-dive-4d4c</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is currently used in my project and works great. Highly recommended!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  I. Implementation Principles &amp;amp; Architecture
&lt;/h2&gt;

&lt;p&gt;HMRouter leverages HarmonyOS's componentized navigation architecture with a three-tier encapsulation for efficient routing management:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application Layer (@HMRouter Annotations) ↔ Routing Management Layer (RouteTable) ↔ System Layer (Navigation Containers)  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1. Annotation-Driven Routing Table
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Automatically generates routing mappings via compile-time annotation processors&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enables type-safe navigation with metadata collection (page paths, parameter validation rules, lifecycle callbacks)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Dynamic Route Stack Management
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Built on NavPathStack for intelligent routing maintenance&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Supports:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nested routing (sub-navigation within containers)&lt;/li&gt;
&lt;li&gt;Cross-module navigation (requires module dependency configuration)&lt;/li&gt;
&lt;li&gt;Route state persistence (stack restoration after app restart)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Enhanced Lifecycle
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Extended lifecycle states:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  export enum PageLifecycle {  
    onCreate = 'onCreate',  
    onShow = 'onShow',  
    onHide = 'onHide',  
    onDestroy = 'onDestroy'  
  }  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  II. Core Usage
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Environment Configuration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// hvigor-config.json  
{  
  "dependencies": {  
    "@hadss/hmrouter": "^1.0.0-rc.6",  
    "@hadss/hmrouter-transitions": "^1.0.0-rc.6"  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Requires compilation plugin configuration in each module's hvigorfile.ts&lt;/p&gt;

&lt;h3&gt;
  
  
  2.2 Route Declaration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Page route definition  
@HMRouter({  
  pageUrl: "LoginActivity",  
  interceptors: [AuthInterceptor] // Global interceptors  
})  
@Component  
export struct LoginPage {  
  // Parameter validation  
  @Validate({  
    name: { type: 'string', required: true },  
    age: { type: 'number', min: 18 }  
  })  
  static routeParams: Record&amp;lt;string, Validator&amp;gt; = {}  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2.3 Navigation Implementation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Basic navigation  
HMRouter.push({  
  pageUrl: "DetailPage",  
  params: { id: 123 },  
  onResult: (res) =&amp;gt; {  
    console.log('Returned data:', res)  
  }  
})  

// Interceptor-enabled navigation  
HMRouter.withInterceptor(AuthInterceptor).push("ProfilePage")  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  III. Technical Advantages
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1 Modular Development Support
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Compile-time checks for unregistered routes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dependency isolation via module.json declarations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamic loading with @LazyRoute&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.2 Advanced Features
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Implementation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Transition Animations&lt;/td&gt;
&lt;td&gt;JSON-configurable scaling/fade/ shared-element animations&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Service Routes&lt;/td&gt;
&lt;td&gt;@ServiceRoute for cross-component access&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Permission Checks&lt;/td&gt;
&lt;td&gt;Annotation-based authorization (e.g., @RequirePermission("READ_CONTACTS"))&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  3.3 Performance Metrics
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Cold startup routing resolution latency: &amp;lt;20ms (vs. 50ms for native Navigation)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Unlimited theoretical stack depth (memory-dependent)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;40% regex validation optimization&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  IV. Comparison with Alternatives
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4.1 vs. Native Navigation
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;HMRouter&lt;/th&gt;
&lt;th&gt;Native Navigation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Route Interception&lt;/td&gt;
&lt;td&gt;✔️ Global/local&lt;/td&gt;
&lt;td&gt;❌ None&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Transition Animations&lt;/td&gt;
&lt;td&gt;✔️ Custom JSON&lt;/td&gt;
&lt;td&gt;✔️ Basic only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Compile-time Validation&lt;/td&gt;
&lt;td&gt;✔️ Type safety&lt;/td&gt;
&lt;td&gt;❌ Runtime only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cross-module Navigation&lt;/td&gt;
&lt;td&gt;✔️ Dependency required&lt;/td&gt;
&lt;td&gt;❌ Not supported&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  4.2 vs. TheRouter
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;HMRouter&lt;/th&gt;
&lt;th&gt;TheRouter&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Routing Protocol&lt;/td&gt;
&lt;td&gt;Annotation-based&lt;/td&gt;
&lt;td&gt;Annotation + code registration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cross-platform&lt;/td&gt;
&lt;td&gt;HarmonyOS only&lt;/td&gt;
&lt;td&gt;Android/iOS/Harmony&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dynamic Routing&lt;/td&gt;
&lt;td&gt;❌ Full rebuild&lt;/td&gt;
&lt;td&gt;✔️ Hot-update&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lifecycle Control&lt;/td&gt;
&lt;td&gt;✔️ Extended callbacks&lt;/td&gt;
&lt;td&gt;✔️ Basic only&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  V. Best Practices
&lt;/h2&gt;

&lt;h3&gt;
  
  
  5.1 E-commerce Routing Scheme
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Cart page configuration  
@HMRouter({  
  pageUrl: "CartPage",  
  interceptors: [LoginInterceptor, CartValidationInterceptor],  
  transitions: {  
    enter: { type: 'slide', direction: 'right' },  
    exit: { type: 'fade' }  
  }  
})  
@Component  
export struct CartPage {  
  // Automatic parameter validation  
  static validateParams(params: Record&amp;lt;string, any&amp;gt;) {  
    return params.items.every(item =&amp;gt; item.id &amp;gt; 0)  
  }  
}  

// Validation on navigation  
HMRouter.push("CartPage", { items: [101,102] })  
  .catch(err =&amp;gt; console.error('Validation failed:', err))  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5.2 Multi-module Architecture
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app-root/  
├── entry-module/       # Main entry  
│   └── src/  
│       └── main/ets/  
│           └── pages/  
│               └── MainActivity.ets  
├── feature-module/     # Feature modules  
│   ├── build.gradle  
│   └── src/  
│       └── main/ets/  
│           └── routes.json  # Module route declarations  
└── shared-module/      # Shared services  
    └── src/  
        └── main/ets/  
            └── services/    # Shared service routes  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>harmonyos</category>
    </item>
    <item>
      <title>HarmonyOS Card Development Technical Guide</title>
      <dc:creator>魔眼天王</dc:creator>
      <pubDate>Wed, 25 Jun 2025 11:48:38 +0000</pubDate>
      <link>https://dev.to/moyantianwang/harmonyos-card-development-technical-guide-1f13</link>
      <guid>https://dev.to/moyantianwang/harmonyos-card-development-technical-guide-1f13</guid>
      <description>&lt;h2&gt;
  
  
  I. Card Development Architecture
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1.1 System Service Framework
&lt;/h3&gt;

&lt;p&gt;HarmonyOS Cards are built on a distributed capability framework with a layered architecture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application Layer (UIAbility) ↔ Card Service Layer (FormExtensionAbility) ↔ System Service Layer (CardService)  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​UIAbility: Handles card UI rendering and interaction logic&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​FormExtensionAbility: Manages card lifecycle and data interaction&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​CardService: Provides system-level resource scheduling and permission control&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1.2 Core Component Model
&lt;/h3&gt;

&lt;p&gt;Card development includes three core components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;​FormBindingData: Data binding container supporting JSON/XML injection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​ComponentProvider: UI component factory for dynamic loading&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​EventDispatcher: Central event handler for interactions (clicks/long-presses)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  II. Development Workflow &amp;amp; Key Technologies
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Environment Configuration
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Requirement&lt;/th&gt;
&lt;th&gt;Specification&lt;/th&gt;
&lt;th&gt;Validation Criteria&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;SDK Version&lt;/td&gt;
&lt;td&gt;DevEco Studio 4.1+&lt;/td&gt;
&lt;td&gt;Supports ArkTS 3.0+&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Device Requirements&lt;/td&gt;
&lt;td&gt;Real device requires EMUI 12+/HarmonyOS 3.0+&lt;/td&gt;
&lt;td&gt;Verified via adb devices&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Permission Declaration&lt;/td&gt;
&lt;td&gt;ohos.permission.SYSTEM_ALERT_WINDOW&lt;/td&gt;
&lt;td&gt;Explicit declaration in config.json&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  2.2 Lifecycle Management
&lt;/h3&gt;

&lt;p&gt;Card lifecycle includes six critical phases:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;graph TD  
    A[onCreateForm] --&amp;gt; B[onStart]  
    B --&amp;gt; C[onActive]  
    C --&amp;gt; D[onInactive]  
    D --&amp;gt; E[onBackground]  
    E --&amp;gt; F[onDestroy]  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Cold Start Optimization: Component pre-loading reduces startup latency by 300ms&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​State Persistence: UI state maintained via @State annotation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2.3 Dynamic Data Interaction
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Data binding implementation  
@Entry  
@Component  
struct WeatherCard {  
  @State temperature: string = "25℃"  

  build() {  
    Column() {  
      Text(this.temperature)  
        .fontSize(24)  
        .fontWeight(FontWeight.Bold)  
      Text("Sunny")  
        .fontSize(18)  
    }  
  }  
}  

// Data update mechanism  
const formBindingData = new FormBindingData();  
formBindingData.set("temperature", "28℃");  
this.updateForm(formId, formBindingData);  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  III. Card Types &amp;amp; Implementation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1 Service Card Categories
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Size Specification&lt;/th&gt;
&lt;th&gt;Typical Use Cases&lt;/th&gt;
&lt;th&gt;Development Complexity&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Basic Card&lt;/td&gt;
&lt;td&gt;2x2&lt;/td&gt;
&lt;td&gt;Weather/Clock/Battery&lt;/td&gt;
&lt;td&gt;★☆☆☆☆&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Container Card&lt;/td&gt;
&lt;td&gt;2x4&lt;/td&gt;
&lt;td&gt;Multi-info aggregation&lt;/td&gt;
&lt;td&gt;★★★☆☆&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Media Card&lt;/td&gt;
&lt;td&gt;4x4&lt;/td&gt;
&lt;td&gt;Video thumbnails/Player&lt;/td&gt;
&lt;td&gt;★★★★☆&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Interactive Card&lt;/td&gt;
&lt;td&gt;Adaptive&lt;/td&gt;
&lt;td&gt;Quick action entry&lt;/td&gt;
&lt;td&gt;★★★★★&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  3.2 Advanced Features
&lt;/h3&gt;

&lt;h4&gt;
  
  
  3.2.1 Cross-Device Transfer
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Device data synchronization  
const deviceManager = deviceManager.getDefaultDeviceManager();  
deviceManager.on('deviceConnect', (device) =&amp;gt; {  
  this.formBindingData.sync(device);  
});  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3.2.2 Responsive Layout
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Responsive layout configuration  
@media (min-width: 600px) {  
  .main-container {  
    flex-direction: row;  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  IV. Case Studies
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4.1 Smart Home Control
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Device control card implementation  
class DeviceControlCard extends Component {  
  @Prop device: DeviceInfo  

  build() {  
    Button("Toggle")  
      .onClick(() =&amp;gt; {  
        this.device.togglePower()  
      })  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4.2 Connected Vehicle Applications
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​HUD Projection Cards: Real-time navigation display&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Vehicle Status Monitoring: Battery/Tire pressure visualization&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;HarmonyOS card development delivers efficient multi-device interaction through innovative distributed architecture and declarative UI frameworks. Strategic use of dynamic data binding ensures functional richness while maintaining performance optimization. With continuous ecosystem enhancements, cards are poised to revolutionize smart home and connected vehicle experiences.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>harmonyos</category>
    </item>
    <item>
      <title>Deep Dive into HarmonyOS AttributeModifier</title>
      <dc:creator>魔眼天王</dc:creator>
      <pubDate>Wed, 25 Jun 2025 11:34:02 +0000</pubDate>
      <link>https://dev.to/moyantianwang/deep-dive-into-harmonyos-attributemodifier-2h0k</link>
      <guid>https://dev.to/moyantianwang/deep-dive-into-harmonyos-attributemodifier-2h0k</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Recently working on focus management, I encountered issues with incomplete focus border displays. After extensive investigation, I discovered AttributeModifier - a powerful yet non-invasive solution for dynamic attribute control.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  I. Core Concepts &amp;amp; Architecture
&lt;/h2&gt;

&lt;p&gt;AttributeModifier is a dynamic attribute modification interface provided by HarmonyOS ArkUI framework. By implementing method families like applyNormalAttribute() and applyPressedAttribute(), developers can dynamically control component properties across interaction states. Its architecture comprises three key layers:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. State Perception Layer
&lt;/h3&gt;

&lt;p&gt;Triggers corresponding methods through built-in component states (default/pressed/focused/disabled/selected). Example: Press state activates applyPressedAttribute()&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Attribute Injection Layer
&lt;/h3&gt;

&lt;p&gt;Injects custom modifier instances via .attributeModifier() during component initialization or state changes, supporting cross-component reuse&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Dynamic Parameter Layer
&lt;/h3&gt;

&lt;p&gt;Enables runtime style control through class member variables combined with @State&lt;/p&gt;

&lt;h2&gt;
  
  
  II. Practical Applications
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Polymorphic Style Management
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Button polymorphic style definition  
export class ThemeButtonModifier implements AttributeModifier&amp;lt;ButtonAttribute&amp;gt; {  
  applyNormalAttribute(instance: ButtonAttribute) {  
    instance.backgroundColor(Color.Blue)  
  }  
  applyPressedAttribute(instance: ButtonAttribute) {  
    instance.backgroundColor(Color.DarkBlue)  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unified theming for form controls and button state consistency&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Dynamic Theme Switching
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@State isDarkMode: boolean = false  
build() {  
  Button("Toggle Theme")  
    .attributeModifier(new DynamicThemeModifier(this.isDarkMode))  
    .onClick(() =&amp;gt; this.isDarkMode = !this.isDarkMode)  
}  

class DynamicThemeModifier implements AttributeModifier&amp;lt;ButtonAttribute&amp;gt; {  
  private isDark: boolean = false  
  constructor(dark: boolean) { this.isDark = dark }  
  applyNormalAttribute(instance: ButtonAttribute) {  
    instance.backgroundColor(this.isDark ? Color.Black : Color.White)  
    instance.fontColor(this.isDark ? Color.White : Color.Black)  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Avoids hard-coded colors for global theme responsiveness&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Business Logic Integration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export class AuthButtonModifier implements AttributeModifier&amp;lt;ButtonAttribute&amp;gt; {  
  private isVIP: boolean = false  
  setVIPStatus(status: boolean) { this.isVIP = status }  
  applyNormalAttribute(instance: ButtonAttribute) {  
    instance.backgroundColor(this.isVIP ? Color.Gold : Color.Gray)  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dynamically adjusts component states based on user permissions&lt;/p&gt;

&lt;h2&gt;
  
  
  III. API Comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;AttributeModifier&lt;/th&gt;
&lt;th&gt;&lt;a class="mentioned-user" href="https://dev.to/styles"&gt;@styles&lt;/a&gt;&lt;/th&gt;
&lt;th&gt;@Extend&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cross-file reusability&lt;/td&gt;
&lt;td&gt;✔️ Supported&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dynamic parameters&lt;/td&gt;
&lt;td&gt;✔️ Via class vars&lt;/td&gt;
&lt;td&gt;❌ Compile-time&lt;/td&gt;
&lt;td&gt;❌ Compile-time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Component-specific&lt;/td&gt;
&lt;td&gt;✔️ Partial&lt;/td&gt;
&lt;td&gt;❌ Generic&lt;/td&gt;
&lt;td&gt;✔️ Full&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Event handling&lt;/td&gt;
&lt;td&gt;✔️ onClick/etc&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;❌ Basic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Full polymorphism&lt;/td&gt;
&lt;td&gt;✔️ Complete&lt;/td&gt;
&lt;td&gt;❌ Default&lt;/td&gt;
&lt;td&gt;❌ Default&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  IV. Limitations
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;​Attribute Restrictions​&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;No support for CustomBuilder or lambda properties&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cannot modify private properties (e.g., TextPicker.visibleItems)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;​State Management Requirements​&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Manual handling of property override precedence&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Complex components need multi-modifier synchronization&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;​Performance Considerations​&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Frame rate drops 10-15% with &amp;gt;3 modifiers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Frequent state changes (&amp;gt;5/s) may cause rendering delays&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  V. Implementation Best Practices
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Style Isolation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Separate color &amp;amp; layout logic  
class ColorModifier implements AttributeModifier&amp;lt;TextAttribute&amp;gt; {  
  applyNormalAttribute(instance: TextAttribute) {  
    instance.fontColor(this.textColor)  
  }  
}  

class LayoutModifier implements AttributeModifier&amp;lt;TextAttribute&amp;gt; {  
  applyNormalAttribute(instance: TextAttribute) {  
    instance.fontSize(16)  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. State Management Optimization
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class BaseModifier&amp;lt;T&amp;gt; implements AttributeModifier&amp;lt;T&amp;gt; {  
  protected themeColor: ResourceColor = Color.Blue  
  updateTheme(color: ResourceColor) {  
    this.themeColor = color  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>harmonyos</category>
    </item>
    <item>
      <title>HarmonyOS System Popup Architecture Guide</title>
      <dc:creator>魔眼天王</dc:creator>
      <pubDate>Tue, 24 Jun 2025 10:11:05 +0000</pubDate>
      <link>https://dev.to/moyantianwang/harmonyos-system-popup-architecture-guide-58bf</link>
      <guid>https://dev.to/moyantianwang/harmonyos-system-popup-architecture-guide-58bf</guid>
      <description>&lt;h2&gt;
  
  
  I. System Popup Classification
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1.1 Modal Dialogs (Strong Interaction)
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1.1.1 Dialog
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Features: Full-screen overlay, blocks all underlying interactions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Use Cases: Critical operations confirmation (delete/exit), form submission&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Official Example:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  // Show confirmation dialog  
  promptAction.showDialog({  
    title: 'Delete Confirmation',  
    message: 'Are you sure to delete this file?',  
    buttons: [Text('Cancel'), Text('Confirm')]  
  });  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Advantages: Clear interaction flow&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Limitations: Frequent use degrades user experience&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  1.1.2 Action Menu
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Features: Bottom-aligned list with multiple options&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Use Cases: Feature selection (share/settings)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Implementation:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  promptAction.showActionMenu({  
    title: 'Select Action',  
    buttons: [Text('Share'), Text('Save')]  
  });  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Advantages: Quick access to key functions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Limitations: Max 5 options before pagination required&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1.2 Non-modal Dialogs (Weak Interaction)
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1.2.1 Loading Dialog
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Features: Auto-centered with progress animation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Use Cases: Network requests, data processing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Usage:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  // Show loading  
  loadingDialog.show({ message: 'Saving...' });  
  // Hide  
  loadingDialog.hide();  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Advantages: Unified loading state management&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Limitations: No custom animation support&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  1.2.2 Tooltip
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Features: Anchor-based positioning, auto-aligns to components&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Use Cases: Icon explanations, operation guides&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Implementation:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  @Component  
  struct Tooltip {  
    build() {  
      Popup() {  
        Text('Click to save changes')  
      }  
      .target(anchorRef)  
      .placement(Placement.Bottom)  
    }  
  }  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Advantages: Precise contextual guidance&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Limitations: Fixed display duration&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  II. Advanced Implementation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Navigation Dialog
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Features: Page-routing based with transparent background&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Configuration:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  @Entry  
  @Component  
  struct MainView {  
    build() {  
      NavDestination() {  
        Column() {  
          Button("Show Dialog")  
            .onClick(() =&amp;gt; this.showDialog())  
        }  
        .mode(NavDestinationMode.DIALOG)  
      }  
    }  
  }  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Use Cases: Form filling, image preview&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Key Consideration: Back button handling required&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2.2 Global Overlay
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;​Implementation:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  // Create global overlay  
  const overlay = OverlayManager.createComponent(  
    new ComponentContent().setComponent(alertComponent)  
  );  
  overlay.show();  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Typical Applications: Floating customer service buttons&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Limitations: Manual lifecycle management&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  III. Best Practices
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1 Design Specifications
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Max Duration&lt;/th&gt;
&lt;th&gt;Min Trigger Distance&lt;/th&gt;
&lt;th&gt;Animation Duration&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Dialog&lt;/td&gt;
&lt;td&gt;Unlimited&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;300ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Loading&lt;/td&gt;
&lt;td&gt;30s&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;200ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tooltip&lt;/td&gt;
&lt;td&gt;5s&lt;/td&gt;
&lt;td&gt;48dp&lt;/td&gt;
&lt;td&gt;250ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  3.2 Performance Optimization
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Memory: Call dispose() promptly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rendering: Enable willMount preloading for complex dialogs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Animations: Prefer system-native animations&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  3.3 Common Scenarios
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Scenario 1: Form Validation
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TextInput()  
  .onChange((text) =&amp;gt; {  
    if(text.length &amp;lt; 6) formValidator.showWarning('Minimum 6 characters');  
  });  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Scenario 2: Multi-step Guide
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@State currentStep = 0;  
build() {  
  Stack() {  
    MainContent()  
    if(currentStep === 1) {  
      GuideOverlay()  
        .content("Click top-right to complete")  
        .onClose(() =&amp;gt; currentStep = 2);  
    }  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  IV. Key Considerations
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;​Permissions: System dialogs don't require special permissions. Custom dialogs need ohos.permission.SYSTEM_ALERT_WINDOW&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Style Consistency: Use @style for global theming:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   @style GlobalDialogStyle {  
     backgroundColor: Color.Transparent;  
     borderRadius: 8;  
   }  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;​Accessibility: Mandatory accessibilityLabel property&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Lifecycle: Avoid showing dialogs in onInit&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>harmony</category>
    </item>
    <item>
      <title>HarmonyOS Tap-to-Share Protocol Development Guide</title>
      <dc:creator>魔眼天王</dc:creator>
      <pubDate>Tue, 24 Jun 2025 09:54:20 +0000</pubDate>
      <link>https://dev.to/moyantianwang/harmonyos-tap-to-share-protocol-development-guide-34hd</link>
      <guid>https://dev.to/moyantianwang/harmonyos-tap-to-share-protocol-development-guide-34hd</guid>
      <description>&lt;h2&gt;
  
  
  I. Protocol Architecture &amp;amp; Technical Evolution
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1.1 Distributed Communication Stack
&lt;/h3&gt;

&lt;p&gt;HarmonyOS Tap-to-Share Protocol employs a dual-mode architecture combining NFC and NearLink 2.0, enabling sub-second connection establishment within 10cm range. Core protocol layers include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;​Physical Layer: Supports adaptive switching between 13.56MHz NFC band and 6.5Gbps NearLink transmission&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Transport Layer: UDP-Lite protocol ensures reliable data transmission in weak network conditions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Application Layer: Standardized HDP protocol format supporting 8 data types (text/images/links/commands)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1.2 Protocol Evolution
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Key Features&lt;/th&gt;
&lt;th&gt;Performance Gains&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;td&gt;Basic file transfer&lt;/td&gt;
&lt;td&gt;50 MB/s transfer rate&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2.0&lt;/td&gt;
&lt;td&gt;Wi-Fi sharing capability&lt;/td&gt;
&lt;td&gt;Pairing time &amp;lt;0.3s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3.0&lt;/td&gt;
&lt;td&gt;Cloud-edge encryption&lt;/td&gt;
&lt;td&gt;Auth time &amp;lt;50ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4.0&lt;/td&gt;
&lt;td&gt;Cross-device service calls&lt;/td&gt;
&lt;td&gt;Service discovery &amp;lt;20ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  II. Core Use Cases &amp;amp; Implementation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 File Transfer Mechanism
&lt;/h3&gt;

&lt;p&gt;​Workflow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;NFC triggers NearLink channel establishment on device contact&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Protocol negotiation prioritizing NearLink 2.0&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;256KB encrypted chunk transmission&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Integrity verification before automatic app preview&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;​Code Example (File Sharing)​:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Sender configuration  
const shareData: ShareData = {  
  type: ShareType.FILE,  
  data: fileUri.getUriFromPath("/data/share.jpg"),  
  thumbnail: generateThumbnail(fileUri),  
  metadata: {  
    description: "Project Proposal",  
    tags: ["work", "urgent"]  
  }  
};  

// Trigger tap-to-share  
harmonyShare.startKnockShare(shareData, (result) =&amp;gt; {  
  if(result.code === 0) console.log("Share succeeded");  
});  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2.2 Offline Payment Solution
&lt;/h3&gt;

&lt;p&gt;Alipay HarmonyOS Edition implements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;NearLink encrypted credential transmission&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Local signature verification (no cloud dependency)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;99.99% success rate with &amp;lt;80ms latency&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2.3 Cross-Device Service Invocation
&lt;/h3&gt;

&lt;p&gt;​Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Service registration  
const service = new Service({  
  name: "printer",  
  methods: ["printPDF"],  
  onInvoke: (params) =&amp;gt; printService.handle(params)  
});  

// Auto-register on contact  
harmonyShare.onServiceRegister(service);  

// Receiver invocation  
const printer = await harmonyShare.getService("printer");  
await printer.invoke({ file: docUri });  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  III. Development Guide
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1 Environment Requirements
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Requirement&lt;/th&gt;
&lt;th&gt;Specification&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;OS Version&lt;/td&gt;
&lt;td&gt;HarmonyOS NEXT 5.0.0.102+&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hardware&lt;/td&gt;
&lt;td&gt;NFC+NearLink dual-mode chipset (Kirin 9000S+)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Development Tools&lt;/td&gt;
&lt;td&gt;DevEco Studio 4.1+&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  3.2 Key APIs
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;​Service Registration​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Entry  
@Component  
struct ShareService {  
  @State isSharing: boolean = false;  

  build() {  
    Column() {  
      Button("Enable Sharing")  
        .onClick(() =&amp;gt; harmonyShare.registerService({  
          serviceId: "com.example.share",  
          dataTypes: [DataType.IMAGE]  
        }));  
    }  
  }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;​Event Handling​
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Listen for tap events  
harmonyShare.on('knock', (event) =&amp;gt; {  
  if(event.data.type === 'IMAGE') previewImage(event.data.uri);  
});  

// Cleanup on component unmount  
onStop(() =&amp;gt; harmonyShare.off('knock'));  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3.3 Error Handling
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Error Code&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Solution&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1001&lt;/td&gt;
&lt;td&gt;NFC disabled&lt;/td&gt;
&lt;td&gt;Guide to settings&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2003&lt;/td&gt;
&lt;td&gt;Protocol mismatch&lt;/td&gt;
&lt;td&gt;Fallback to basic mode&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3005&lt;/td&gt;
&lt;td&gt;Payload size exceeded&lt;/td&gt;
&lt;td&gt;Chunking/compression&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4002&lt;/td&gt;
&lt;td&gt;Service unregistered&lt;/td&gt;
&lt;td&gt;Verify registration&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  IV. Security &amp;amp; Privacy
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4.1 Five-Layer Protection
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;​Dynamic Key Exchange: Session-specific keys per interaction&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Memory Sandbox: Zero disk persistence during transfer&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​TEE-based Device Fingerprinting​&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Audit Logging: Full event traceability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Emergency Breaker: Automatic connection termination&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  4.2 Privacy Compliance
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Minimal data collection (business-critical only)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mandatory user consent for sensitive operations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Metadata sanitization in shared content&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  V. Industry Applications
&lt;/h2&gt;

&lt;h3&gt;
  
  
  5.1 Healthcare
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Cross-device EHR access (doctor-nurse terminals)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Medical device integration via PDA contact&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5.2 Industrial IoT
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;PLC controller data retrieval via smartphone contact&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;AR maintenance guidance through equipment interaction&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5.3 Retail
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Contactless payments via refrigerator interaction&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Smart shelf-based product recommendations&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  VI. Challenges &amp;amp; Roadmap
&lt;/h2&gt;

&lt;h3&gt;
  
  
  6.1 Technical Challenges
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Multi-device interference management&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NearLink module power optimization&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cross-brand compatibility&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6.2 Development Roadmap (2025)
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;​Bluetooth Mesh Support​&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​AI Intent Prediction​ (context-aware UI popups)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;​Seamless Cross-Device Flow​ (mobile-PC-vehicle continuity)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>harmonyos</category>
    </item>
  </channel>
</rss>
