🤖 안드로이드 Android
[안드로이드/Android] 기기 단말정보 가져오기 (단말ID, 제조사, 브랜드, 모델명, OS버전, SDK 버전)
핑크빛연어
2021. 4. 23. 09:00
안드로이드 휴대폰의 기기 단말정보 를 가져오는 코드입니다.
DeviceInfoUtil 라는 Util 파일을 만들고
MainActivity 에서 DeviceInfoUtil 의 정보를 가져오는 메소드를 이용하여 로그로 출력해보았습니다.
작성한 파일 목록 입니다.
1. DeviceInfoUtil.java
2. MainActivity.java
1. DeviceInfoUtil.java
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
public class DeviceInfoUtil {
/**
* device id 가져오기
* @param context
* @return
*/
public static String getDeviceId(Context context) {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
/**
* device 제조사 가져오기
* @return
*/
public static String getManufacturer() {
return Build.MANUFACTURER;
}
/**
* device 브랜드 가져오기
* @return
*/
public static String getDeviceBrand() {
return Build.BRAND;
}
/**
* device 모델명 가져오기
* @return
*/
public static String getDeviceModel() {
return Build.MODEL;
}
/**
* device Android OS 버전 가져오기
* @return
*/
public static String getDeviceOs() {
return Build.VERSION.RELEASE;
}
/**
* device SDK 버전 가져오기
* @return
*/
public static int getDeviceSdk() {
return Build.VERSION.SDK_INT;
}
}
2. MainActivity.java
public class MainActivity extends AppCompatActivity {
private String TAG = MainActivity.class.getSimpleName();
private Context context = MainActivity.this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "--- getDeviceId : "+getDeviceId(context)); //device id
Log.d(TAG, "--- getManufacturer : "+getManufacturer()); //제조사
Log.d(TAG, "--- getDeviceBrand : "+getDeviceBrand()); //브랜드
Log.d(TAG, "--- getDeviceModel : "+getDeviceModel()); //모델명
Log.d(TAG, "--- getDeviceOs : "+getDeviceOs()); //안드로이드 OS 버전
Log.d(TAG, "--- getDeviceSdk : "+getDeviceSdk()); //안드로이드 SDK 버전
}
}
감사합니다 ~ 😄
728x90
반응형