How to Get Device ID

palmzac

Active Member
Licensed User
Longtime User
Hi,

I am newbie on Basic4Android. I don't understand the document of Phone Library. I want to get DeviceID. Would you give me a sample code ?

Thanks !

palmzac
 
Try this:

Sub Globals
Dim PhoneId As PhoneId
End Sub

Sub Activity_Create(FirstTime As Boolean)
Msgbox(PhoneId.GetDeviceId, "Your device ID")
End Sub
 
Upvote 0
or this one :

Code: Copy
Dim DeviceID1 As PhoneId
Dim DevID As String 
DevID = DeviceID1.GetDeviceId
If DevID = "" Then
   Dim Device As Phone
   DevID = Device.GetSettings("android_id")
End If
 
Upvote 0
And... don't forget to to put a checkmark in the correct phone library in the Libs tab of the B4A editor. I can't tell you exactly which one, I'm not at my dev pc right now. If there is a lib called PhoneId, use it, otherwise use the standard Phone lib. You'll know you got the right one when you start typing 'As PhoneId' and PhoneId is in the popup list if available objects.

Cheers
 
Upvote 0
I guess one has also to add the permission in the manifest
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
 
Upvote 0
I guess one has also to add the permission in the manifest
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

No, B4A does that for you. The library's author is responsible for instructing B4A which permissions each of their objects use, and its all handled behind the scenes at compile time. Note that a library can have multiple objects, and unless I am mistaken, only the Dimmed objects will cause permissions to be reported.
 
Upvote 0

Similar Threads

Replies
6
Views
11K
  • Locked
  • Article Article
Android Code Snippet Advertising id
Replies
19
Views
25K
  • Question Question
Android Question Device ID
Replies
4
Views
5K
Back
Top