首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何获得IMEI号

如何获得IMEI号
EN

Stack Overflow用户
提问于 2018-05-07 10:13:14
回答 1查看 2.7K关注 0票数 1

我需要从Android设备上获取IMEI,我在一个离子应用程序中工作。

我正在使用这个插件- ionic cordova plugin add cordova-plugin-uid

参考链接- https://ionicframework.com/docs/native/uid/

这是我的代码片段-

代码语言:javascript
复制
async getIMEI() {

    const {hasPermission} = await this.androidPermissions.checkPermission(
        this.androidPermissions.PERMISSION.READ_PHONE_STATE
    );

    console.log("hasPermission : " + hasPermission);
    if (!hasPermission) {
        const result = await this.androidPermissions.requestPermission(
            this.androidPermissions.PERMISSION.READ_PHONE_STATE
        );

        if (!result.hasPermission) {
            throw new Error('Permissions required');
        }

        // ok, a user gave us permission, we can get him identifiers after restart app
        return 0 ;
    }

    return this.uid.IMEI;
}

我在构造函数中调用getIMEI() -

代码语言:javascript
复制
 constructor(public navCtrl: NavController, public navParams: NavParams, public alertCtrl: AlertController,
                public apiProvider: ApiProvider, public storage: Storage, public platform: Platform, public fcm: FCM,
                public uid: Uid, public androidPermissions: AndroidPermissions) {


        platform.ready().then(() => {

            if (this.platform.is('android')) {
                console.log("running on Android device!");
                this.deviceType = 'ANDROID';
                this.getIMEI();
            }
            if (this.platform.is('ios')) {
                console.log("running on iOS device!");
                this.deviceType = 'IPHONE';
            }



        });
    }

我总是将IMEI编号作为值。

EN

回答 1

Stack Overflow用户

发布于 2019-12-27 06:16:44

您可以跟踪docs:https://ionicframework.com/docs/native/uid

首先,将插件添加到应用程序中:

代码语言:javascript
复制
ionic cordova plugin add cordova-plugin-uid
npm install @ionic-native/uid     

在ts文件中,您希望获得IMEI:

代码语言:javascript
复制
import { Uid } from '@ionic-native/uid/ngx';
import { AndroidPermissions } from '@ionic-native/android-permissions/ngx';

constructor(private uid: Uid, private androidPermissions: AndroidPermissions) { }


async getImei() {
 const { hasPermission } = await this.androidPermissions.checkPermission(
   this.androidPermissions.PERMISSION.READ_PHONE_STATE
 );

 if (!hasPermission) {
   const result = await this.androidPermissions.requestPermission(
     this.androidPermissions.PERMISSION.READ_PHONE_STATE
   );

   if (!result.hasPermission) {
     throw new Error('Permissions required');
   }

   // ok, a user gave us permission, we can get him identifiers after restart app
   return;
 }

  return this.uid.IMEI
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50211792

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档