Breaking change: Android 6 and device IDs

Breaking change: Android 6 and device IDs

Before the release of Android 6, users were regularly asked to grant permissions when installing new apps. Often times users were asked to grant the android.permission.READ_PHONE_STATE permission, which is considered a dangerous permission. This caused many people to not install apps for fear of what the apps might be doing with that granted permission.

Android 6 eases those fears by moving permissions to an on-demand system. Now you can request android.permission.READ_PHONE_STATE when your app needs it. However, this change creates an issue with the Corona SDK API that allows you to get the device’s device ID using system.getInfo("deviceID").

If the user’s device grants the android.permission.READ_PHONE_STATE permission, then the device’s unique phone ID (IMEI, MEID or ESN depending on the carrier) is returned. For devices without a phone or which have not granted the permission, a unique system ID assigned by the operating system is returned.

If your app currently uses the deviceID value, it’s very likely that any users who upgrade to Android 6 will have a different deviceID than they had with earlier versions of Android. If it is important to your app to maintain the same ID, you must take steps to ensure that your app continues to get the phone ID instead of the OS ID.

You can do this in main.lua by requesting the proper android.permission.READ_PHONE_STATE permission before attempting to get the deviceID. Consider this code:

Since the OS-based ID doesn’t require special permissions, we recommend that you standardize on the OS generated ID instead of the Phone ID moving forward.

Have questions? Join us in the Corona Labs Android forum!

 

Tags:
Rob Miracle
[email protected]

Rob is the Developer Relations Manager for Corona Labs. Besides being passionate about helping other developers make great games using Corona, he is also enjoys making games in his spare time. Rob has been coding games since 1979 from personal computers to mainframes. He has over 16 years professional experience in the gaming industry.

4 Comments
  • Felix
    Posted at 16:40h, 25 February

    I am trying to implement this code, but it gives a runtime error because system.getInfo( “androidApiLevel” ) returns nil. I implemented a check for Android, like
    if system.getInfo( “platformName” ) == “Android” then
    but it even return nil on android devices. any idea whats the problem here?

    Best,
    Felix

    • Felix
      Posted at 17:11h, 25 February

      Ah, never mind. Updating corona to the newest public build resolved the problem…

  • Charlotte Hook
    Posted at 04:00h, 13 March

    Since a newer version of android is being released, does this mean some older versions of android will no longer be compatible? the only article i can find is from april 2014 which says 2.3.3 is the earliest now compatible, just wondering if this will change

    • Rob Miracle
      Posted at 12:15h, 13 March

      We still support a minimum of 2.3.3 on Android, but we don’t know how much longer that will be the case. More and more plugins are asking for features that want a higher minimum. It won’t happen in the near future since we just released a pubic build that still supports 2.3.3 in February.