Android Question How to get the mobile number in the mobile device/sim cards in that device on which my app is installed ?

beelze69

Active Member
Licensed User
Longtime User
Hi,

I would like to get the mobile number of the device on which my app is installed.

Now a mobile number can be stored in a sim card or it may be stored inside the mobile device.

Need help on :

i) detecting the number of sim cards in that device

ii) get the mobile numbers on the sim cards

iii) if it is the case that the number is stored inside the mobile device, get the mobile number from that mobile device.

In this regard I tried the post at:


This displays a BLANK for the Phone Number.

Then I tried the post at :


in which user Invocker responded
And made the foll. entry in the manifest :

AddPermission(android.permission.READ_PHONE_STATE)

However I am getting the error which is pasted in the code portion below...


Please note that I am reposting my request since I did not get the solution to my earlier request of 25th December,2022.


Please help.
Thanks.

B4X:
Logger connected to: Xiaomi Redmi Note 7 Pro
--------- beginning of system
--------- beginning of main
Logger connected to: Xiaomi Redmi Note 7 Pro
--------- beginning of system
--------- beginning of main
--------- beginning of crash
java.lang.RuntimeException: Unable to create service b4a.example.starter: java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io_OutputStream.write(byte[])' on a null object reference
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4026)
at android.app.ActivityThread.access$1600(ActivityThread.java:227)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7592)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io_OutputStream.write(byte[])' on a null object reference
at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:164)
at anywheresoftware.b4a.shell.Shell.start(Shell.java:102)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94)
at b4a.example.starter.onCreate(starter.java:34)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4014)
... 8 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io_OutputStream.write(byte[])' on a null object reference
at anywheresoftware.b4a.shell.ShellConnector.sendControlMessage(ShellConnector.java:61)
at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:124)
... 12 more
 

peacemaker

Expert
Licensed User
Longtime User
Recent years the mobile phone number among all other personal info is the private personal data, that must not be easily published without the person agreement.
So, IMHO, most of vendors disable it especially.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Recent years the mobile phone number among all other personal info is the private personal data, that must not be easily published without the person agreement.
So, IMHO, most of vendors disable it especially.
The General Data Protection Regulation (GDPR) sees all information that can be traced back to a living person as personal data, which must be properly protected. For this reason, Google has increasingly stricter rules for including an app in the playstore. Personally, I am not very fond of all kinds of messages that are sent to me inappropriately. If you let the user provide a password with which you put something in an encrypted keystore, the user is responsible for it and after entering that password the program can transfer the data from the encrypted and with the given password of the user over the stored have information. This saves you the effort of managing, updating and securing that data.
 
Upvote 0
Top