簡體   English   中英

如何獲得IMEI號碼| 離子 | 安卓

[英]How to get IMEI Number | IONIC | Android

我需要從 Android 設備獲取 IMEI,我正在使用 IONIC 應用程序。

我正在使用這個插件 - ionic cordova plugin add cordova-plugin-uid

參考鏈接 - https://ionicframework.com/docs/native/uid/

這是我的代碼片段 -

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 號碼作為值。

您可以按照文檔: https : //ionicframework.com/docs/native/uid

首先將插件添加到您的應用程序:

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

在你想要獲取 IMEI 的 ts 文件中:

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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM