Tried calling native plugin, but not found in runtime

I am trying to read Uid.IMEI from Ionic Native Uid plugin. I handled the runtime permission issue for Android 6 using Diagnostic, and then tried to read Uid.IMEI. But it is showing

Native: tried calling Uid.IMEI, but the Uid plugin is not installed.
Install the Uid plugin: 'ionic cordova plugin add https://github.com/hygieiasoft/cordova-plugin-uid'

I have tried removing and then re-installing the plugin. The issue is , this message is shown only after installing the app and then opening it . Later on, I don’t find this msg , rather IMEI is read perfectly .

here is the code snippet…

 getPermission() {

    this.diagnostic.getPermissionAuthorizationStatus(this.diagnostic.permission.READ_PHONE_STATE).then((status) => {
     
      if (status != this.diagnostic.permissionStatus.GRANTED) {

        this.diagnostic.requestRuntimePermission(this.diagnostic.permission.READ_PHONE_STATE).then((data) => {
         
          var imei = this.uid.IMEI;
          console.log("in promise imei "+ imei);
        })
      }
      else {
        console.log("We have the permission");
        console.log("IMEI granted ----------"+this.uid.IMEI);
      }


    }, (statusError) => {
      console.log(`statusError`);
      console.log(statusError);
    });
  }

After installing the app, the requestRuntimePermission block is executed and after user accepts , Uid plugin tried to read IMEI, here my app does not find the plugin ! After that, I exit the app, reopen it , then see the permission is already granted and IMEI is found.

IMEI granted ----------

I saw some solutions referring to async/await. I am using Ionic framework 2 , and can’t update to Ionic 3 now, since my project is a bit complex. Plz suggest anyone if it can be solved avoiding async/await.

Where are you calling getPermission() from?
If you’re calling it when the app launches, try calling it after the platform is ready, like so

this.platform.ready().then(()=>{
getPermission();
}

and call it outside the constructor (maybe inside ionViewDidLoad() or so).
Good luck!

I have called it within ionViewDidEnter() and platform.ready , but no luck ! First time after installing app, it is showing same msg,

tried calling Uid.IMEI, but the Uid plugin is not installed

After exiting app, reopening it, then shows the proper imei :frowning:

Looks like something is causing it not to load when the app launches. Is it properly loaded in app.module.ts?

Did you find any solution for this?
I am also facing the same issue after allowing the permissions it saying that Uid plugin is not installed.
If you solved it.
Please share the solution.

1 Like

Did you find solution for this? I am facing same issue now. is it possible to retrieve the IMEI without restarting the application after installed?

Did you try adding the below in config file

<config-file after="uses-permission" parent="/manifest" target="AndroidManifest.xml">
            <uses-permission android:name="android.permission.READ_PHONE_STATE" />
            <uses-permission android:name="android.permission.SEND_SMS" />
            <uses-permission android:name="android.permission.INTERNET" />
 </config-file>
1 Like

I will try it . Thank you much.

Also test it with real device only.

I think it is not possible without restarting. I think you can use

window.location.reload();

in the page where you are trying to get the IMEI.

Right after user allowing the permissions you have to call window.location.reload();

2 Likes

Thank you, bro. I have write it below and it works. But, while reloading the apps, the white blank page is appearing and it’s awkward to see it.How to remove that ? bro.
Another question is if it’s possible to give android permission as default without asking prompt ? Many Thanks.
if(res.hasPermission){
console.log(“Permitted!”);
}else{
this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.READ_PHONE_STATE).then( res => {

      location.reload(); 
        console.log("Persmission Granted Please Restart App!");
      }).catch(error => {
        console.log("Error! "+error);
      });
    }

Is the plugin working for you now.

For me uid.IMEI is not working but uid.UUID is working

1 Like

uid.IMEI is working for me. You can refer this links and plugins
Getting Device ID

https://www.freakyjolly.com/ionic-4-get-unique-device-id-other-uids-of-uuid-imei-imsi-iccid-and-mac-using-native-cordova-plugins/

ionic cordova plugin add cordova-plugin-unique-device-id2
npm install @ionic-native/unique-device-id
ionic cordova plugin add cordova-plugin-uid
npm install @ionic-native/uid
ionic cordova plugin add cordova-plugin-android-permissions
npm install @ionic-native/android-permissions

Did you try it with android 10 OS?

1 Like

I never tried it before on device since I only have 9.