2016년 2월 19일 금요일

[안드로이드 개발] 자신의 폰 번호 알아내기

1. manifest 파일에 권한 설정 설정
<uses-permission android:name="android.permission.READ_PHONE_STATE" />


2. 원하는 곳에 아래 소스 삽입
TelephonyManager telManager = (TelephonyManager)context.getSystemService(context.TELEPHONY_SERVICE);
String phoneNum = telManager.getLine1Number();

3. TelephonyManager 클래스에 대한 설명

Provides access to information about the telephony services on the device. Applications can use the methods in this class to determine telephony services and states, as well as to access some types of subscriber information. Applications can also register a listener to receive notification of telephony state changes.
안드로이드 기기들의 전화통신 서비스 정보에 대한 접근을 제공합니다. 앱에서 해당 클래스의 메소드를 사용하여 통신 서비스와 통신 상태, 통신 사용자 목록 등도 이용할 수 있습니다. 앱에서 통신상태의 변화가 있을 때 알림을 받기위한 리스너를 등록할 수도 있습니다.
You do not instantiate this class directly; instead, you retrieve a reference to an instance through Context.getSystemService(Context.TELEPHONY_SERVICE).
클래스를 정의하아 바로 사용할 수 없습니다. 대신에 Context.getSystemService(Context.TELEPHONY_SERVICE)를 사용하여 해당 객체의  참조를 얻어 사용할 수 있습니다.
Note that access to some telephony information is permission-protected. Your application cannot access the protected information unless it has the appropriate permissions declared in its manifest file. Where permissions apply, they are noted in the the methods through which you access the protected information.

<출처: http://developer.android.com/reference/android/telephony/TelephonyManager.html >

댓글 없음:

댓글 쓰기