【问题标题】:How to get IMEI Number | IONIC | Android如何获得 IMEI 号码 |离子 |安卓
【发布时间】:2018-05-07 10:13:14
【问题描述】:

我需要从 Android 设备获取 IMEI,我正在使用 IONIC 应用程序。

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

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

这是我的代码 sn-p -

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() -

 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 号码作为 null 值。

【问题讨论】:

  • 您找到解决方案了吗?

标签: android ionic-framework ionic2 imei


【解决方案1】:

您可以关注文档:https://ionicframework.com/docs/native/uid

首先将插件添加到您的应用中:

ionic cordova plugin add cordova-plugin-uid
npm install @ionic-native/uid     

在ts文件中你要获取IMEI:

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
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-07-22
  • 1970-01-01
  • 2012-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-18
  • 1970-01-01
相关资源
最近更新 更多