Android / Get Phone Number, Carrier Name on Android 19-29
2019-08-09
Environments
- Android API 19 - 29
- Kotlin
- Android Studio 3.4
step
MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val tm = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
log("======================================")
if (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkSelfPermission(READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED
} else {
TODO("VERSION.SDK_INT < M")
}
) {
log(tm.line1Number) // +821011112222
}
log(tm.networkCountryIso) // KR
log(tm.networkOperator) // 45080
log(tm.networkOperatorName) // KT
log("==========================================")
}
App Manifest
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
App Permission Check
- Settings -> Applications -> [This App] -> Permission -> Telephone Turn permission On