Android Question GetDeviceId Permission

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am using the licencing lib in my app.

With Android API 26 it requires runtime permissions.

In my manifest I have: <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>

My code looks like:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim publicKey As String
    publicKey = "..nnx0PZUdi3aDAQAB.."
    Private rp As RuntimePermissions    ' RuntimePermissions lib 1.10
    
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)

    rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
    
End Sub

Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = rp.PERMISSION_READ_PHONE_STATE Then
        Dim lc As LicenseChecker
        Dim p As PhoneId
        lc.Initialize("lc", p.GetDeviceId, publicKey, "kljdflkf".GetBytes("UTF8"))
        lc.CheckAccess
    End If
End Sub

The above works, but when it requests the runtime permission it says:

Allow B4A Example to make and mange phone calls?

I am not actually making any phone calls, and only using the permission to request the device ID from the device.

I then read the protect your application tutorial again: https://www.b4x.com/android/forum/t...application-with-the-licensing-library.11429/

It says to use the alternative phone id: http://www.b4x.com/forum/basic4andr...oid-device-unique-id-alternative-phoneid.html

The question I have is, my app was using the p.GetDeviceId and users have been using my app with that. If I then now swap to the alternative phone id, will that cause any issues with my existing users, if so how can I make it so that it doesn't cause any issues when I swap to the alternative phone id ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Allow B4A Example to make and mange phone calls?

I am not actually making any phone calls, and only using the permission to request the device ID from the device.
You cannot do anything about it. This is the required permission to get the device id.

Changing the id means that the device cache will be ignored. Licensing should still work if the device is connected to the internet.
Make sure to test it.
 
Upvote 0
Top