getLine1Number() is not guaranteed to return a valid value. Not all SIM cards know their device's phone number. I know of no way to reliably retrieve the device's phone number. And bear in mind that an increasing number of Android devices are not phones.
On Sat, Sep 3, 2011 at 4:21 PM, Goutom <[email protected]> wrote: > Hi > I want to get my mobile number for a sim in my mobile.I am using the > following code.But it gives me empty string. > package Get.My.PhoneNumber; > import android.app.Activity; > import android.content.Context; > import android.os.Bundle; > import android.telephony.TelephonyManager; > import android.widget.TextView; > public class GetMyPhoneNumberActivity extends Activity { > TextView phn; > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > phn = (TextView) findViewById(R.id.phn); > String s = getMyPhoneNumber(); > phn.setText(s); > } > > private String getMyPhoneNumber(){ > TelephonyManager mTelephonyMgr; > mTelephonyMgr = > (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); > return mTelephonyMgr.getLine1Number(); > } > } > Please suggest me. > Regards > RiskyCoder > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android 3.1 Programming Books: http://commonsware.com/books -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

