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

외부 클래스에서 구현하는 방법 여쭤볼게요

0 추천
	// 안드로이드 기기 식별하는 36자의 String형 반환
	private String GetDevicesUUID(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();

		return deviceId;
	}

위와 같은 코드를 같은 클래스에서는 GetDevicesUUID(this.getApplicationContext()) 하면 오류없이 불러와지는데

 

다른 클래스로 구현하여 (유지보수를 쉽게하기 위해) 

public class Uuid extends Activity {
	private String uuid;

	// 안드로이드 기기 식별하는 36자의 String형 반환
	public Uuid(Context mContext) {
//		Context mContext = this.getApplicationContext();
		
		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;
	}
}

와 같이 다른 클래스에 구현해 놓고,

Uuid u = new Uuid(this.getApplicationContext());
test = u.getUuid();
 
하면 프로그램이 죽어버림니다...
 
아무리 찾아도 방법을 모르겠어요 ㅠㅠ. 고수님들 부탁드립니다.
 
ps.manifast는 전부 정의 했습니다.
Daver (160 포인트) 님이 2014년 11월 16일 질문
로그캣을 확인하세요. 기본입니다.
그리고 액티비티를 왜 상속 받으셨나요? 기본 부터 챙기시고 질문은 나중에 하셔도 될 것 같습니다.

2개의 답변

0 추천
Uuid 클래스에 왜 Activity를 상속시키나요?

Uuid  클래스가 액티비티가 아닌거 같은데......

액티비티를 상속시키지 말고 그냥 클래스 작성해보세요

 

그리고 오류가 나면 에러난 부분의 로그를 올려주시는게

다른분들이 도움 주시기가  쉽습니다

에러 로그를 올려주세요
psalm (1,910 포인트) 님이 2014년 11월 17일 답변
0 추천
보통 이 정도 문제는 로그캣만 보면 원인을 알 수 있을 것 같은데요.

 

로그캣 확인해보세요. 어디가 문제고 어떤 문제인지 알려주니까요.

 

(아니 올려주세요)
익명사용자 (5,930 포인트) 님이 2014년 11월 17일 답변
익명사용자님이 2014년 11월 17일 수정
...