No se muestra el número de teléfono

I have written a simple android application to fetch the phone number... this application is working in Android emulator.... but it is not working in Android mobile phones(both in samsung galaxy s3 and samsung ace).

Aquí está el código fuente.

PhoneNumberActivity.java

public class PhoneNumberActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phone_number);


        final TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.getLine1Number();

        final Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {

                TextView  textView = (TextView) findViewById(R.id.phoneNumber);
                textView.setText("Phone Number is :- "+telephonyManager.getLine1Number());
                button.setVisibility(Button.INVISIBLE);
                textView.setVisibility(TextView.VISIBLE);
            }
        });
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.pervazive.phonenumber"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.phonenumber.PhoneNumberActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 </manifest>

Por favor avíseme cuál es el problema.

preguntado el 23 de abril de 13 a las 13:04

1 Respuestas

Según la documentación .getLine1Number() "Returns the phone number string for line 1, for example, the MSISDN para agendar una GSM phone. Return null if it is unavailable. "

Aparentemente .getLine1Number() reads this information from SIM card, so if the operator has set the MSISDN field it will return you its value and null if they did not set this field.

In your case probably your SIM card does not have this field populated by operator.

For More Info You can Visita esto.

Tengo esto de aquí.

contestado el 23 de mayo de 17 a las 12:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.