Is it possible to get own phone number?

StuartM

Member
Licensed User
Longtime User
A search suggests that, subject to SIM security, this is possible in Java via:

B4X:
TelephonyManager tMgr =(TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
  mPhoneNumber = tMgr.getLine1Number();

But is this possible in B4A?

It doesn't matter if it is unreliable, it would just be a "default" to avoid some app users having to type their own number into an app set-up screen.

(Obligatory, sorry 1st post apology goes here Got the trial last night and bought today so still learning.)
 

molder26

Member
Licensed User
Longtime User
i check Phone.GetLine1Number but i catch a error and app stoped after that.
i am using a really simple code:

Sub Process_Globals
Dim ph1 As Phone​
End Sub

Sub Activity_Create(FirstTime As Boolean)
ToastMessageShow("Sim: " & ph1.GetSimSerialNumber , True)​
End Sub

In Emulator it run perfect, but in my cellphone only show me an error.
Thanks

mou
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User

Was the error for GetLine1Number or GetSimSerialNumber, and what was the error.
 
Upvote 0

molder26

Member
Licensed User
Longtime User
hi kickaha, i try with both (GetLine1Number and GetSimSerialNumber), the error is the same.
Only say: !We sorry!, The application test (process number.test) is stoped. Try again.
Have any way to see the real error in some log in the phone?
I have phone lib updated.
Thanks!

mou
 
Upvote 0

molder26

Member
Licensed User
Longtime User
Hi Erel, i check the unfiltered logs, but i cant find the problem.
The program run perfect in emulator, but in real device get the error.
And i cant use my cellphone with usb driver, so i need copy the .apk to the real device, install it and run from cellphone.
Do you have anyway to find the error?
Thanks for all
Regards
 
Upvote 0

molder26

Member
Licensed User
Longtime User
Thanks Erel, i cant install the b4a bridge, because when i try i get an error in b4a bridge install, it say "The program can't be installed in this phone".
This phone have android 1.5 can be it the problem?
Regards
 
Upvote 0

tremara1

Active Member
Licensed User
Longtime User
Try This

Here is a small offering....
 

Attachments

  • myPhnZip.zip
    243.8 KB · Views: 920
Upvote 0

molder26

Member
Licensed User
Longtime User
thanks tremara, but this example only run in 1.6 and above as Erel say.
I need some unique ID for cellphone with android 1.5, we cant update the devices for the warranty.
Thanks in advance!
Regards
 
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Thanks Tremara1 for your "small" offering.

I think I'll need this to use on my app one day, but first I have to
solve my imageview problem.

Maybe it's useful to others by putting the zip in the tutorial/example section?

grtz.
Asmoro
 
Upvote 0

molder26

Member
Licensed User
Longtime User
I did it with reflection lib:

Dim Obj1 As Reflector
Dim LineNumber As String
Obj1.Target = Obj1.GetContext
Obj1.Target = Obj1.RunMethod2("getSystemService", "phone", "java.lang.String")
LineNumber = Obj1.RunMethod ("getLine1Number")

In my case, android 1.5 doesn't support Phone lib, so with reflector lib we can use it.
Regards
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
Hi

I am trying to get phone it own number in order to create some activation licensing, I am using these
ToastMessageShow(pi.GetSimSerialNumber,True)
ToastMessageShow(pi.GetDeviceId,True)
ToastMessageShow(pi.GetSubscriberId,True)
ToastMessageShow(pi.GetLine1Number,True)

only lines 1-3 are ok, the line that I need is giving blank result
I need full prove solution to get phone number (since I will base my entire licensing on it)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…