phone number in EditText - android

I am having a form wherein i get user details, in that i have field called phone number and Edit Text to put phone number.
i have feeling that it would be great if that edittext automatically get filled by user phone number.
is there any method which automatically fills user phone number with national code??
below code was posted on stackoverflow i think it might work in some instances can anyone help me for same?
private String getMyPhoneNumber() {
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
return mTelephonyMgr.getLine1Number();
}

i have feeling that it would be great if that edittext automatically get filled by user phone
number
To solve the above problem, your best bet is to use,
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String number = tm.getLine1Number();
with the permission added of course
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
But the problem is that the documentation for getLine1Number() says this method will return null if the number is "unavailable", but it does not say when the number might be unavailable.
is there any method which automatically fills user phone number with national code??
To solve this issue, unfortunately there doesn't seem to be a direct way to get the user's current country code. But since country codes don't ever change, it is acceptable to hard code a lookup table in your application.
<?xml version='1.0' encoding='UTF-8'?>
<icc>
<AF>93</AF>
<AL>355</AL>
<DZ>213</DZ>
<AD>376</AD>
<AO>244</AO>
<AQ>672</AQ>
<AR>54</AR>
<AM>374</AM>
<AW>297</AW>
<AU>61</AU>
<AT>43</AT>
<AZ>994</AZ>
<BH>973</BH>
<BD>880</BD>
<BY>375</BY>
<BE>32</BE>
<BZ>501</BZ>
<BJ>229</BJ>
<BT>975</BT>
<BO>591</BO>
<BA>387</BA>
<BW>267</BW>
<BR>55</BR>
<BN>673</BN>
<BG>359</BG>
<BF>226</BF>
<MM>95</MM>
<BI>257</BI>
<KH>855</KH>
<CM>237</CM>
<CA>1</CA>
<CV>238</CV>
<CF>236</CF>
<TD>235</TD>
<CL>56</CL>
<CN>86</CN>
<CX>61</CX>
<CC>61</CC>
<CO>57</CO>
<KM>269</KM>
<CG>242</CG>
<CD>243</CD>
<CK>682</CK>
<CR>506</CR>
<HR>385</HR>
<CU>53</CU>
<CY>357</CY>
<CZ>420</CZ>
<DK>45</DK>
<DJ>253</DJ>
<TL>670</TL>
<EC>593</EC>
<EG>20</EG>
<SV>503</SV>
<GQ>240</GQ>
<ER>291</ER>
<EE>372</EE>
<ET>251</ET>
<FK>500</FK>
<FO>298</FO>
<FJ>679</FJ>
<FI>358</FI>
<FR>33</FR>
<PF>689</PF>
<GA>241</GA>
<GM>220</GM>
<GE>995</GE>
<DE>49</DE>
<GH>233</GH>
<GI>350</GI>
<GR>30</GR>
<GL>299</GL>
<GT>502</GT>
<GN>224</GN>
<GW>245</GW>
<GY>592</GY>
<HT>509</HT>
<HN>504</HN>
<HK>852</HK>
<HU>36</HU>
<IN>91</IN>
<ID>62</ID>
<IR>98</IR>
<IQ>964</IQ>
<IE>353</IE>
<IM>44</IM>
<IL>972</IL>
<IT>39</IT>
<CI>225</CI>
<JP>81</JP>
<JO>962</JO>
<KZ>7</KZ>
<KE>254</KE>
<KI>686</KI>
<KW>965</KW>
<KG>996</KG>
<LA>856</LA>
<LV>371</LV>
<LB>961</LB>
<LS>266</LS>
<LR>231</LR>
<LY>218</LY>
<LI>423</LI>
<LT>370</LT>
<LU>352</LU>
<MO>853</MO>
<MK>389</MK>
<MG>261</MG>
<MW>265</MW>
<MY>60</MY>
<MV>960</MV>
<ML>223</ML>
<MT>356</MT>
<MH>692</MH>
<MR>222</MR>
<MU>230</MU>
<YT>262</YT>
<MX>52</MX>
<FM>691</FM>
<MD>373</MD>
<MC>377</MC>
<MN>976</MN>
<ME>382</ME>
<MA>212</MA>
<MZ>258</MZ>
<NA>264</NA>
<NR>674</NR>
<NP>977</NP>
<NL>31</NL>
<AN>599</AN>
<NC>687</NC>
<NZ>64</NZ>
<NI>505</NI>
<NE>227</NE>
<NG>234</NG>
<NU>683</NU>
<KP>850</KP>
<NO>47</NO>
<OM>968</OM>
<PK>92</PK>
<PW>680</PW>
<PA>507</PA>
<PG>675</PG>
<PY>595</PY>
<PE>51</PE>
<PH>63</PH>
<PN>870</PN>
<PL>48</PL>
<PT>351</PT>
<PR>1</PR>
<QA>974</QA>
<RO>40</RO>
<RU>7</RU>
<RW>250</RW>
<BL>590</BL>
<WS>685</WS>
<SM>378</SM>
<ST>239</ST>
<SA>966</SA>
<SN>221</SN>
<RS>381</RS>
<SC>248</SC>
<SL>232</SL>
<SG>65</SG>
<SK>421</SK>
<SI>386</SI>
<SB>677</SB>
<SO>252</SO>
<ZA>27</ZA>
<KR>82</KR>
<ES>34</ES>
<LK>94</LK>
<SH>290</SH>
<PM>508</PM>
<SD>249</SD>
<SR>597</SR>
<SZ>268</SZ>
<SE>46</SE>
<CH>41</CH>
<SY>963</SY>
<TW>886</TW>
<TJ>992</TJ>
<TZ>255</TZ>
<TH>66</TH>
<TG>228</TG>
<TK>690</TK>
<TO>676</TO>
<TN>216</TN>
<TR>90</TR>
<TM>993</TM>
<TV>688</TV>
<AE>971</AE>
<UG>256</UG>
<GB>44</GB>
<UA>380</UA>
<UY>598</UY>
<US>1</US>
<UZ>998</UZ>
<VU>678</VU>
<VA>39</VA>
<VE>58</VE>
<VN>84</VN>
<WF>681</WF>
<YE>967</YE>
<ZM>260</ZM>
<ZW>263</ZW>
</icc>

Please set that phonenumber in your edittext like this edittext.setText(mTelephonyMgr.getLine1Number())

There is plenty of questions relating to this.
Your method relies on the phonenumber being stored on the sim, which it rarely is.
The most reliable method is to let users input the number themselves. Though it would not hurt to let the getLine1Number() method try and set the number first.
I have chosen to let my app send a SMS to the number with an unique message, which when received, completes the verification of the input number. The number then finally is stored in a sharedPreference.
This method of course runs short if the user changes sim but if you need to handle that, it could be done by also saving the IMEI so that it can be checked when app starts.

Related

Obtaining data from my TP-Link router programmatically

I'm trying to design an app that can communicate with my router programmatically using the same endpoints as the web interface (there's a demo on TP-Link's website). My router is a TP-Link TD-W8980, if that matters.
The format appears to be very difficult to decipher. Here is a request which obtains the data for the status part of my app. This can obtain a valid response from the router but I'm not sure why!
I'm especially confused by the #0,0,0,0,0,0#0,0,0,0,0,0] part of the response. It's the only part I haven't managed to work out but I think I recall reading it's to do with the stack?!?
[SYS_MODE#0,0,0,0,0,0#0,0,0,0,0,0]0,1
mode
[LAN_HOST_CFG#1,0,0,0,0,0#0,0,0,0,0,0]1,1
DNSServers
[WAN_DSL_INTF_CFG#1,0,0,0,0,0#0,0,0,0,0,0]2,8
upstreamCurrRate
downstreamCurrRate
upstreamMaxRate
downstreamMaxRate
upstreamNoiseMargin
downstreamNoiseMargin
upstreamAttenuation
downstreamAttenuation
[IGD_DEV_INFO#0,0,0,0,0,0#0,0,0,0,0,0]3,3
softwareVersion
hardwareVersion
upTime
[LAN_IP_INTF#0,0,0,0,0,0#0,0,0,0,0,0]4,2
IPInterfaceIPAddress
X_TPLINK_MACAddress
[LAN_HOST_ENTRY#0,0,0,0,0,0#0,0,0,0,0,0]5,4
leaseTimeRemaining
MACAddress
hostName
IPAddress
[WAN_PPP_CONN#0,0,0,0,0,0#0,0,0,0,0,0]6,4
enable
connectionStatus
externalIPAddress
DNSServers
If it helps, the names in capitals (e.g. SYS_MODE) is the name of the section. The number after the ] is a counter stating the section number (sections can be in any order). The final number following the , is the number of parameters that follow in this section.
There are also request types for each section. In the example above, the URL is http://192.168.1.1/cgi?1&1&1&1&5&5&5. As you can see the two main request types are 1 and 5.
Here is an example response from the server. As you can see, some of the sections can be returned more than once, which makes the first number of the six zeros increment each time.
[0,0,0,0,0,0]0
mode=DSL
[1,0,0,0,0,0]1
DNSServers=x.x.x.x,x.x.x.x
[1,0,0,0,0,0]2
upstreamCurrRate=928
downstreamCurrRate=3072
upstreamMaxRate=1068
downstreamMaxRate=3104
upstreamNoiseMargin=60
downstreamNoiseMargin=57
upstreamAttenuation=295
downstreamAttenuation=546
[0,0,0,0,0,0]3
softwareVersion=0.6.0 1.3 v000e.0 Build 131012 Rel.51720n
hardwareVersion=TD-W8980 v1 00000000
upTime=x
[1,1,0,0,0,0]4
IPInterfaceIPAddress=192.168.1.1
X_TPLINK_MACAddress=xx:xx:xx:xx:xx:xx
[1,0,0,0,0,0]5
leaseTimeRemaining=-1
MACAddress=xx:xx:xx:xx:xx:xx
hostName=X
IPAddress=192.168.1.2
[2,0,0,0,0,0]5
leaseTimeRemaining=-1
MACAddress=xx:xx:xx:xx:xx:xx
hostName=X
IPAddress=192.168.1.4
[3,0,0,0,0,0]5
leaseTimeRemaining=-1
MACAddress=xx:xx:xx:xx:xx:xx
hostName=X
IPAddress=192.168.1.11
[4,0,0,0,0,0]5
leaseTimeRemaining=-1
MACAddress=xx:xx:xx:xx:xx:xx
hostName=X
IPAddress=192.168.1.5
[1,2,1,0,0,0]6
enable=1
connectionStatus=Connected
externalIPAddress=x.x.x.x
DNSServers=x.x.x.x,x.x.x.x
[2,1,1,0,0,0]6
enable=0
connectionStatus=Unconfigured
externalIPAddress=0.0.0.0
DNSServers=0.0.0.0,0.0.0.0
[3,1,1,0,0,0]6
enable=0
connectionStatus=Unconfigured
externalIPAddress=0.0.0.0
DNSServers=0.0.0.0,0.0.0.0
[error]0
I would appreciate any explanation of this format and if it appears anywhere else on the web. I've never seen such a system before!

Reply to SMS in VBS

My question for you today is "How to reply to an email using windows vbscript." (Gmail) That may not be the best explanation...
WAIT, I already know how to SEND an email (to my phone through phonenumber#txt.att.net) using VBScript, but I want to reply to a text. I have a system that alerts my phone when an action is performed on my computer (through VBScript) but this keeps happening. It's as if I receive the message from a different address each and every time.
So, is there any way to make it so I receive the text from the same recipient each time? Currently, the "phone" number of the sender started at 1410200500 and counts up every time I send it using this vbs code.
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 1
Const cdoSendUsingPort = 2
Set oMsg = CreateObject("CDO.Message")
oMsg.From = "myemail#gmail.com"
oMsg.To = "myphonenumber#txt.att.net"
oMsg.TextBody = "ALERTMSG"
Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver") = "smtp.gmail.com"
oConf.Fields(schema & "smtpserverport") = 465
oConf.Fields(schema & "sendusing") = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic
oConf.Fields(schema & "smtpusessl") = True
oConf.Fields(schema & "sendusername") = "myemail#gmail.com"
oConf.Fields(schema & "sendpassword") = "supersecretpassword"
oConf.Fields.Update
oMsg.Send
Everything works except for the issue of the sender being different each time.
Please help
Edit: I have found that this is unavoidable, thanks to everyone that helped!
There is nothing wrong with your VBScript or the CDO configuration.
The value assigned to the Sender by the SMS Middleware that takes the e-mail and forwards it to an SMS service is outside your control. The only option you have is to contact your SMS provider but I wouldn't suggest they will change how this works.
In fact in this Video at 0:40 it states;
"the number that appears on your recipients phone or device may not be your actual phone number, but they will see the name, subject and e-mail address you used to send the text message."
Useful Links
Send email as text message (AT&T Support)

Formatting phone number to match

I'm new to android development. I am trying to make an SMS app. Everything works fine already except for phone number formatting. Say for example, I live in the Philippines and I got 2 different SMS from the same number.
First SMS address: +639123456789
Second SMS address: 09123456789
+639123456789 must equal to 09123456789
Or Swiss number +41446681800 must equal to 0446681800
Now how can I format either of these addresses that they will match. String manipulation will work but it's limited for Philippines only. I found this libphonenumber but I have no idea how to use it on my current project. Sorry for being noob. Any help would be much appreciated.
Here you can find an example for libphonenumber lib.
Using this library you can convert those numbers into international format, after you can match the numbers and if you want, you can get the country code too.
internationalFormatMobileNumber = phoneUtil.format(yourNumber, PhoneNumberFormat.INTERNATIONAL);
If you know the country for which you want to do it, you can use Google's open source library https://github.com/googlei18n/libphonenumber . Here is how you can format it:
String numberStr = "8885551234"
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try {
PhoneNumber numberProto = phoneUtil.parse(numberStr, "US");
//Since you know the country you can format it as follows:
System.out.println(phoneUtil.format(numberProto, PhoneNumberFormat.NATIONAL));
} catch (NumberParseException e) {
System.err.println("NumberParseException was thrown: " + e.toString());
}

Android geocoder reverse location - reliable way to get the city?

I have searched quite a bit without luck so far.
The Android Geocoder returns the android.location.Address object.
The city, as far as I understood, should be returned in getLocality().
It seems within USA this works well, outside not.
I am writing an international app and struggle to find a solution to find out the city of a geolocation.
Here the output from Czech Republic/Prague :
Address[addressLines=
[0:"Psohlavců 1764/2",
1:"147 00 Prague-Prague 4",
2:"Czech Republic"],
feature=2,
admin=Hlavní město Praha,
sub-admin=Prague,
locality=null,
thoroughfare=Psohlavců,
postalCode=147 00,
countryCode=CZ,
countryName=Czech Republic,
hasLatitude=true,
latitude=50.0276543,
hasLongitude=true,
longitude=14.4183926,
phone=null,
url=null,
extras=null]
locality is null, the city is within sub-admin !
The address itself is ok, so the geocoder server seems to know the city.
Here some ore random EU examples but locality works partly:
Address[addressLines=[0:"Nad lesem 440/34",1:"147 00 Prague-Prague 4",2:"Czech Republic"],feature=34,admin=Hlavní město Praha,sub-admin=Prague,locality=null,thoroughfare=Nad lesem,postalCode=147 00,countryCode=CZ,countryName=Czech Republic,hasLatitude=true,latitude=50.02424,hasLongitude=true,longitude=14.4117568,phone=null,url=null,extras=null]
Address[addressLines=[0:"Hauner Straße 4",1:"84431 Heldenstein",2:"Germany"],feature=4,admin=null,sub-admin=null,locality=Heldenstein,thoroughfare=Hauner Straße,postalCode=84431,countryCode=DE,countryName=Germany,hasLatitude=true,latitude=48.2540274,hasLongitude=true,longitude=12.3413535,phone=null,url=null,extras=null]
Address[addressLines=[0:"Igler Straße",1:"6020 Innsbruck",2:"Austria"],feature=Igler Straße,admin=Tyrol,sub-admin=Innsbruck,locality=Innsbruck,thoroughfare=Igler Straße,postalCode=6020,countryCode=AT,countryName=Austria,hasLatitude=true,latitude=47.2465698,hasLongitude=true,longitude=11.4054237,phone=null,url=null,extras=null]
Address[addressLines=[0:"Durnberg 24",1:"5724 Stuhlfelden",2:"Austria"],feature=24,admin=Salzburg,sub-admin=Zell am See District,locality=null,thoroughfare=Durnberg,postalCode=5724,countryCode=AT,countryName=Austria,hasLatitude=true,latitude=47.3233373,hasLongitude=true,longitude=12.4960482,phone=null,url=null,extras=null]
Address[addressLines=[0:"U Roháčových kasáren 14",1:"100 00 Prague 10",2:"Czech Republic"],feature=14,admin=Hlavní město Praha,sub-admin=Prague,locality=Prague 10,thoroughfare=U Roháčových kasáren,postalCode=null,countryCode=CZ,countryName=Czech Republic,hasLatitude=true,latitude=50.0704092,hasLongitude=true,longitude=14.4673473,phone=null,url=null,extras=null]
Maybe the fault is on me, but to me it seems like depending on the country and area the city will be found in different fields.
However, the address itself mostly seems to be good enough to send a postal letter.
Has someone written a clever function which tries to make more sense out of the Geocoder results ? It's a pity to see that Google has the information stored but does not provide it properly.
Going to close my question, solved it with a workaround.
Using the suggestion from dannyroa
String city="unknown";
if (address.getLocality() != null) city=address.getLocality();
else
if (address.getSubAdminArea() != null) city=address.getSubAdminArea();
This could be further extended by getting the city information out of the second address line.
removing the postal code and taking the remainder, but this information is not unique within a city and could change depending on the district/zone.

Regular expression to match all phone numbers

I have tried matching Phone numbers with the regular expressions provided by Android in Patterns.Phone,this matches a lot of things that are not phone numbers.I have also tried using:
(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?
However,I found that the Test was not successfull for all the inputs.I would like to validate the following inputs using a regular expression:
67450450
+9144-27444444
27444444
27470570
+12142261347
+61406366180
0891 2577456
2577456
+91 9550461668
9550461668
03-1234567
1860 425 3330
Basically any nymber format supported here:WTND
you can use the following code to check phone #:
private boolean validPhone(String phone) {
Pattern pattern = Patterns.PHONE;
return pattern.matcher(phone).matches();
}
if(validPhone("67450450")){
Toast.makeText(this,"The phone number is valid");
}
else
{
Toast.makeText(this,"The phone number is not valid");
}
This isn't clean/efficient, just thrown together to match your sample data:
\b\d{7,10}|\+\d{4}-\d{8}|\+\d{11}|\d{4}\s\d{7}|\+\d{2}\s\d{10}|\d{2}-\d{7}|\d{4}\s\d{3}\s\d{4}\b

Categories

Resources