Witam.
Chciałbym się dowiedzieć czy jest jakaś metoda na automatyczne pobranie numeru telefonu na którym zainstalowana będzie aplikacja.
Znalazłem coś takiego:
Plik manifest
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Plik java
TextView number = (TextView) findViewById(R.id.number);
TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
number.setText(tManager.getLine1Number());
Plik activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
Problem w tym, że na avd wywala błąd i zamyka aplikację - pewnie dlatego, że nie może znaleźć numeru,
natomiast na zwykłym telefonie nic nie zwraca