I have struck with implementing Read Device id . This is my code
and this is my manifest code
While I run , this error displays :
java.lang.SecurityException: getDeviceId: Neither user 10314 nor current process has android.permission.READ_PHONE_STATE.
I could not understand where am I wrong .
B4X:
Sub Globals
Dim pid As PhoneId
Dim rp As RuntimePermissions
End Sub
Sub Activity_Create(FirstTime As Boolean)
lblid.Initialize("")
lblid.TextColor = Colors.White
lblid.TextSize = 20
Activity.AddView(lblid,5%x,5%y,90%x,40dip)
txtKey.Initialize("")
txtKey.TextSize = 20
Activity.AddView(txtKey,5%x,20%y,90%x,40dip)
btnOK.Initialize("btnOK")
btnOK.TextColor = Colors.Black
btnOK.TextSize = 22
btnOK.Text = "O K"
Activity.AddView(btnOK,40%x,50%y,20%x,40dip)
rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
did = pid.GetDeviceId
Msgbox(did,"")
lblid.Text = "DeviceId :" & " " & did
End Sub
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
AddManifestText(
<uses-permission
android:name="android.permission.READ_PHONE_STATE"
android:maxSdkVersion="26" />
)
java.lang.SecurityException: getDeviceId: Neither user 10314 nor current process has android.permission.READ_PHONE_STATE.
I could not understand where am I wrong .