Wednesday, September 17, 2014
Android 내폰번호 구하기
안드로이드 내 핸드폰 번호 얻는 소스이다.
잘동작하는데 국내에서 주의할 사항은 SKT/LGT는 010****####으로 나오는데 KT는 +8210****####으로 나온다는 점이다.
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
package com.example.line1number;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TelephonyManager tm = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
// Getting my phone number
String myNumber = tm.getLine1Number();
TextView model = (TextView) findViewById(R.id.phonenumber);
model.setText("[" + myNumber + "] length=" + myNumber.length());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Labels:
Android
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment