Hongmeng's js Development Department mode 17: Application module of Hongmeng's system capability

Hongmeng introductory guide, Xiaobai, come quickly! 0 basic learning route sharing, efficient learning methods, key question answering and puzzle solving -- > [course entrance]

catalog:

1. Notification module

2. Power information module

3. Location information module

4. Screen brightness information module

5. Equipment information module

6. Collection of articles on Hongmeng's js development model

1. Hongmeng's system capability mainly involves the notification message module, which can also be practiced and obtained in the simulator

Initial interface:

Click send notification, and the icon of notification message will appear at the top

Pull down the notification menu bar to display the notification information:

Business logic code of js:

import notification from '@system.notification';

    notification.show({
            contentTitle: 'Page notification message',
            contentText: 'Hongmeng will be released in April. Please look forward to it!',
            clickAction: {
                bundleName: 'com.example.jscode3',
                abilityName: 'MainAbility',
                uri: '/path/menuone/menuone',
            },
        });

contentTitle: notification title. contentText - notification content.

bundleName the bundleName of the application to jump to after clicking the notification

abilityName the abilityName of the application to jump to after clicking the notification

uri 

The uri to jump to can be in the following two formats:

The absolute path of the page is provided by the pages list in the configuration file, for example: pages/index/index
pages/detail/detail
In particular, if the value of uri is "/", jump to the first page.

 

2. Hongmeng's system capability mainly involves the power information module, which can also be practiced and obtained in the simulator

Business logic code of js:

import battery from '@system.battery';  

     battery.getStatus({
            success: function(data) {
                console.log('success get battery level:' + data.level);

                prompt.showToast({
                    message:"The current power is:"+data.level+","+(data.charging==true?'Charging':"No charging"),
                    duration:8000

                });

            },
            fail: function(data, code) {
                console.log('fail to get battery level code:' + code + ', data: ' + data);
            },
        });

charging whether the battery is currently being charged. level current battery capacity, value range: 0.00 - 1.00.

 

3. Hongmeng's system capability mainly involves the location information module, which can also be practiced and obtained in the simulator

 

Open the location service in the simulator and click agree:

 

Click the location information to obtain the current longitude and latitude data:

 

Apply for permission

Business logic code of js:

import geolocation from '@system.geolocation';

     geolocation.getLocation({
            success: function(data) {
                console.log('success get location data. latitude:' + data.latitude);
                prompt.showToast({
                    message:"Now the longitude is:"+data.longitude+",Latitude is"+data.latitude,
                    duration:8000

                });
            },
            fail: function(data, code) {
                console.log('fail to get location. code:' + code + ', data:' + data);
            },
        });

 

By obtaining longitude and latitude data, reporting data and combining with Huawei cloud platform, you can use maps very well and combine with corresponding services.

 

4. Hongmeng's system capability mainly involves the screen brightness information module, which can also be practiced and obtained in the simulator

By adjusting the brightness

Get again:

 

Business logic code of js:

import brightness from '@system.brightness';

    brightness.getValue({
            success: function(data){
                console.log('success get brightness value:' + data.value);
                prompt.showToast({
                    message:"The brightness of the screen is:"+data.value,
                    duration:8000

                });
            },
            fail: function(data, code) {
                console.log('get brightness fail, code: ' + code + ', data: ' + data);
            },
        });

 

5. Hongmeng's system capability mainly involves the equipment information module, which can also be practiced and obtained in the simulator

Business logic code of js:

import device from '@system.device';
     device.getInfo({
           success: function(data) {
               console.log('Device information obtained successfully. Device brand:' + data.brand);
               let  infos="Brand is:"+data.brand+",manufacturer"+data.manufacturer+",What is the model of the mobile phone:"+data.model+",The code of the mobile phone is:"+data.product+",Language is:"+
                        data.language+",System area"+data.region+",The shape of the device is:"+data.screenShape;

               prompt.showToast({
                   message:"The mobile phone information is:"+infos,
                   duration:8000

               });

           },
           fail: function(data, code) {
               console.log('Failed to obtain device information. Error code:'+ code + '; Error information: ' + data);
           },
       });

Hongmeng system was put into commercial use in April. I believe Hongmeng has excellent ability! Come on, welcome the whole scene of Hongmeng!

Author: Liuhe Li Xin

For more information, please visit: Hongmeng technology community jointly built by 51CTO and Huawei's official strategic cooperation https://harmonyos.51cto.com

Tags: Javascript harmonyos

Posted by preston_stone on Sat, 16 Apr 2022 04:30:55 +0930