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.

Please help.

Thank you.
 

invocker

Active Member
B4X:
         Dim manager As JavaObject
Dim context As JavaObject
            context.InitializeContext
          manager = manager.InitializeStatic("android.telephony.SubscriptionManager").RunMethod("from", Array(context))
            Dim infos As List = manager.RunMethod("getActiveSubscriptionInfoList", Null)
        For Each info As JavaObject In infos
        Log(info.RunMethod("getDisplayName", Null) & info.RunMethod("getNumber", Null))
        next
 
Upvote 0

beelze69

Active Member
Licensed User
Longtime User
Add this line to the manifest editor:

B4X:
AddPermission(android.permission.READ_PHONE_STATE)
Hi,

I added that line to the Manifest.

I am getting the following error :
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

What could be the issue ?
Please help.
Thanks.
 
Upvote 0

invocker

Active Member
I think that the write() method is trying to be called on the object which is null (OutputStream). check the output stream object for a null reference
 
Upvote 0

beelze69

Active Member
Licensed User
Longtime User
I think that the write() method is trying to be called on the object which is null (OutputStream). check the output stream object for a null reference
Hi !
Sorry !
I don't understand Java...
Can you please tell me exactly what I should do ?
Thanks ...
 
Upvote 0
Top