Hi All,
How to get mobile number of our sim.(all sim provider does not provide facility to get number so it best to get device id).
Step 1:
Put this in AndroidManifest.xml(Don't Forget.)
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Step 2:
String netork="";
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
if(cm.getActiveNetworkInfo().getTypeName().equals("MOBILE"))
network = "cellnetwork/3G";
else if(cm.getActiveNetworkInfo().getTypeName().equals("WIFI"))
network = "wifi";
else
network ="na";
//give u phone number
String uphone = tm.getLine1Number();
//give u device id
String uphone1 = tm.getDeviceId();
Toast.makeText(getApplicationContext(), uphone, Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), uphone1, Toast.LENGTH_LONG).show();
Enjoy.
How to get mobile number of our sim.(all sim provider does not provide facility to get number so it best to get device id).
Step 1:
Put this in AndroidManifest.xml(Don't Forget.)
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Step 2:
String netork="";
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
if(cm.getActiveNetworkInfo().getTypeName().equals("MOBILE"))
network = "cellnetwork/3G";
else if(cm.getActiveNetworkInfo().getTypeName().equals("WIFI"))
network = "wifi";
else
network ="na";
//give u phone number
String uphone = tm.getLine1Number();
//give u device id
String uphone1 = tm.getDeviceId();
Toast.makeText(getApplicationContext(), uphone, Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), uphone1, Toast.LENGTH_LONG).show();
Enjoy.
No comments:
Post a Comment