마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

Activity 를 상속 받지 않으면 오류가 생겨요...

0 추천
public class Uuid extends Activity {
	private String uuid;

	// 안드로이드 기기 식별하는 36자의 String형 반환
	public Uuid(Context mContext) {
		
		final TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);

		final String tmDevice, tmSerial, androidId;
		tmDevice = "" + tm.getDeviceId();
		tmSerial = "" + tm.getSimSerialNumber();
		androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

		UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
		String deviceId = deviceUuid.toString();

		this.uuid = deviceId;
	}

	public String getUuid() {
		return uuid;
	}
}

위를 액티비티 상속받지 말라고 말씀하셨는데 상속받지 않으면

getContentResolver() 부분이 오류가뜹니다.

그래서 검색하여보니mContext.getApplicationContext() 하라고 해서 해도 해결이 안되네요..

어떻게 해야할까요?... 고수님 조언 부탁드립니다.

kmg123 (1,080 포인트) 님이 2014년 11월 18일 질문

1개의 답변

0 추천
 
채택된 답변
public class Uuid {
    private String uuid;
 
    // 안드로이드 기기 식별하는 36자의 String형 반환
    public Uuid(Context context) {
         
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
 
        final String tmDevice, tmSerial, androidId;
        tmDevice = "" + tm.getDeviceId();
        tmSerial = "" + tm.getSimSerialNumber();
        androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
 
        UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
        String deviceId = deviceUuid.toString();
 
        this.uuid = deviceId;
    }
 
    public String getUuid() {
        return uuid;
    }
}

호출 할때 context.getContentResolver() 하시면 오류가 안나오겠죠?! ^^

 

단짝 (4,980 포인트) 님이 2014년 11월 18일 답변
kmg123님이 2014년 11월 19일 채택됨
설마설마 했는데, 진짜로 이거라면 ㄷㄷㄷ
.... 부끄럽네요.. 하나만 생각하고 둘은 생각치 못한 제가;;; 감사합니다..ㅠㅠ
괜히 뻘짓하고 있었네요... 다시한번 감사합니다.
...