Android Question Error capturing IMEI number in Devices

AndroidMadhu

Active Member
Licensed User
Hello,
I am trying to capture mobile IMEI number of Devices.
While the App working fine at 2 devices. [Xiomi [ Android 10] and Samsung [Android 8.1.0]].
But when I am trying to capture the IMEI number of Samsung Galaxy M30S [Android 10] , the application crash while load/Opening of App.
I have un-installed and again install but no luck.
The below error I am getting while trying to open the App....
B4X:
 ** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main$ResumableSub_Activity_Createresume (java line: 548)
java.lang.SecurityException: getDeviceId: The user 10299 does not meet the requirements to access device identifiers.
at android.os.Parcel.createException(Parcel.java:2088)
at android.os.Parcel.readException(Parcel.java:2056)
at android.os.Parcel.readException(Parcel.java:2004)
at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:11175)
at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:2282)
at anywheresoftware.b4a.phone.Phone$PhoneId.GetDeviceId(Phone.java:441)
at b4a.example.main$ResumableSub_Activity_Create.resume(main.java:548)
at b4a.example.main._activity_create(main.java:405)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at b4a.example.main.afterFirstLayout(main.java:108)
at b4a.example.main.access$000(main.java:20)
at b4a.example.main$WaitForLayout.run(main.java:86)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7814)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)

The below code I am running to capture IMEI number
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim pid As PhoneId
imei=pid.GetDeviceId
Log(imei)
End Sub

Please advice on this......
 

AndroidMadhu

Active Member
Licensed User
Your code cannot work.
@Erel... I am getting error while trying to compile the App...

B4X:
B4A Version: 10.2
Java Version: 11
Parsing code.       (0.13s)
Building folders structure.       (0.03s)
Compiling code.       Error
Error compiling program.
Error description: Cannot cast type: {Type=ResumableSub,Rank=0, RemoteObject=True} {Type=String,Rank=0, RemoteObject=True} to:
Error occurred on line: 139
imei=GetAdvertisingId
Word: getadvertisingid

The below is the Code...
B4X:
 imei=GetAdvertisingId

Java Code
B4X:
 #if Java
import java.util.concurrent.Callable;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;

public static void GetAdvertisingId() {
    BA.runAsync(processBA, mostCurrent, "advertisingid_ready", new Object[] {false, ""}
            , new Callable<Object[]>() {
                                    @Override
                                    public Object[] call() throws Exception {
                                            String id = AdvertisingIdClient.getAdvertisingIdInfo(mostCurrent).getId();
                                            return new Object[] {true, id};
                                    }
                            }); }
#End If

Please advice on this please......
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Hello,
I am trying to capture mobile IMEI number of Devices.
While the App working fine at 2 devices. [Xiomi [ Android 10] and Samsung [Android 8.1.0]].
But when I am trying to capture the IMEI number of Samsung Galaxy M30S [Android 10] , the application crash while load/Opening of App.
I have un-installed and again install but no luck.
The below error I am getting while trying to open the App....
B4X:
 ** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main$ResumableSub_Activity_Createresume (java line: 548)
java.lang.SecurityException: getDeviceId: The user 10299 does not meet the requirements to access device identifiers.
at android.os.Parcel.createException(Parcel.java:2088)
at android.os.Parcel.readException(Parcel.java:2056)
at android.os.Parcel.readException(Parcel.java:2004)
at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:11175)
at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:2282)
at anywheresoftware.b4a.phone.Phone$PhoneId.GetDeviceId(Phone.java:441)
at b4a.example.main$ResumableSub_Activity_Create.resume(main.java:548)
at b4a.example.main._activity_create(main.java:405)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at b4a.example.main.afterFirstLayout(main.java:108)
at b4a.example.main.access$000(main.java:20)
at b4a.example.main$WaitForLayout.run(main.java:86)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7814)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)

The below code I am running to capture IMEI number
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim pid As PhoneId
imei=pid.GetDeviceId
Log(imei)
End Sub

Please advice on this......
You can't run this code anymore in Android 10+.
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
You can't run this code anymore in Android 10+.
I have tested the above code on Xiaomi [Android 10] and Samsung Android Q. Both worked fine for me.
If it will not work on Android 10+, the only way to get the Unique User ID is Advertising ID. But the above code is not working Post #3.

Please advice on this....

Thanks
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
So we know what you're trying to do but we don't know why...
I am developing a Fleet management system. When the App has been installed it will get the Hardware [Phone] IMEI [Which is not working] or Phone Hexadeci ID [Working as of Now] and store into Database.
I want to restrict the user to use the fleet with One Phone ID tagged with fleet. Because of this reason I want to tag the Phone ID with The fleet ID.
Otherwise user[Driver] may use different Fleet with same phone , and I am not able to get the usage of fleet in real time and the tariff/cost for the fleet.

Hope I am able to clear my concept as why I want to get the IMEI or Phone ID.

Thanks
 
Upvote 0
Top