Network
API Reference: Device.Network
Network is used to retrieve information about the network connections and adapters on the device.
TypeScript code blocks include examples of how to implement, override and components within the theme. You can create page with the UI Editor to make your page compatible with theming and then you can implement themable components programmatically. Once the page is created with the UI Editor, it generates a class under scripts/generated/pages. You can then extend that class with the following TypeScript classes.
TypeScript
1
import PageSampleDesign from 'generated/pages/pageSample';
2
import FlexLayout from '@smartface/native/ui/flexlayout';
3
import Application from '@smartface/native/application';
4
import Network from '@smartface/native/device/network';
5
6
//You should create new Page from UI-Editor and extend with it.
7
export default class Sample extends PageSampleDesign {
8
9
constructor() {
10
super();
11
// Overrides super.onShow method
12
this.onShow = onShow.bind(this, this.onShow.bind(this));
13
// Overrides super.onLoad method
14
this.onLoad = onLoad.bind(this, this.onLoad.bind(this));
15
16
this.layout.flexDirection = FlexLayout.FlexDirection.COLUMN;
17
this.layout.justifyContent = FlexLayout.JustifyContent.CENTER;
18
this.layout.alignItems = FlexLayout.AlignItems.CENTER;
19
}
20
}
21
22
/**
23
* @event onShow
24
* This event is called when a page appears on the screen (everytime).
25
* @param {function} superOnShow super onShow function
26
* @param {Object} parameters passed from Router.go function
27
*/
28
function onShow(superOnShow: () => void) {
29
const { headerBar } = this;
30
superOnShow();
31
Application.statusBar.visible = false;
32
headerBar.visible = false;
33
}
34
35
/**
36
* @event onLoad
37
* This event is called once when page is created.
38
* @param {function} superOnLoad super onLoad function
39
*/
40
function onLoad(superOnLoad: () => void) {
41
superOnLoad();
42
43
console.log("Device.Network.IMSI: " + Network.IMSI);
44
console.log("Device.Network.SMSEnabled: " + Network.SMSEnabled);
45
console.log("Device.Network.bluetoothMacAddress: " + Network.bluetoothMacAddress);
46
console.log("Device.Network.carrier: " + Network.carrier);
47
console.log("Device.Network.connectionType: " + Network.connectionType);
48
console.log("Device.Network.roamingEnabled: " + Network.roamingEnabled);
49
console.log("Device.Network.connectionIP: " + Network.connectionIP);
50
console.log("Device.Network.wirelessMacAddress: " + Network.wirelessMacAddress);
51
52
//@ts-ignore
53
let notifier = new Network.createNotifier();
54
55
//@ts-ignore
56
notifier.subscribe((connectionType) => {
57
console.log("ConnectionType is " + connectionType);
58
});
59
}
60
Copied!
Last modified 2mo ago
Copy link