可以在首次接入使用应用时,将获取的PLMN信息存储在一个文件或系统设置中,后续再次使用应用时,则重新获取PLMN信息,与首次存储的PLMN信息进行匹配,进而判断SIM卡是否做过变更。
样例代码如下:
import { BusinessError } from '@kit.BasicServicesKit'; import { sim } from '@kit.TelephonyKit'; @Entry @Component struct Index { // 先获取首次存储PLMN号 plmn: string = 'xxxxxxxxxxx'; getSimOperatorNumeric() { // 获取SIM卡PLMN号 sim.getSimOperatorNumeric(0, (err: BusinessError, data: string) => { console.info(`err: ${err.code} ,PLMN号: ${data}`); if (data === this.plmn) { // SIM卡未变更 } else { // SIM卡已变更 } }); } build() { Column() { Button('getSimOperatorNumeric').onClick(() => { this.getSimOperatorNumeric(); }); }.height('100%') .width('100%') .justifyContent(FlexAlign.SpaceAround); } }