를 구하는 방법 Android에서 Deviceid를 사용 하시겠습니까? 스마트 폰 및 태블릿의 경우. 그것이 내가 unically하지 않을지도 모른다는 것을 이해했기 때문에?DeviceID Android를 얻는 방법?
이 코드가 작동합니까? http://android-developers.blogspot.com/2011/03/identifying-app-installations.html
를 구하는 방법 Android에서 Deviceid를 사용 하시겠습니까? 스마트 폰 및 태블릿의 경우. 그것이 내가 unically하지 않을지도 모른다는 것을 이해했기 때문에?DeviceID Android를 얻는 방법?
이 코드가 작동합니까? http://android-developers.blogspot.com/2011/03/identifying-app-installations.html
이은을 얻는 쉬운 방법은 기기 ID도 알 수 있습니다.
public class DeviceHelper {
private static String sID = null;
private static final String INSTALLATION = "INSTALLATION";
public synchronized static String getDeviceId(final Context context) {
if (sID == null) {
File installation = new File(context.getFilesDir(), INSTALLATION);
try {
if (!installation.exists()){
writeInstallationFile(context,installation);
}
sID = readInstallationFile(installation);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return sID;
}
private static String readInstallationFile(File installation) throws IOException {
RandomAccessFile f = new RandomAccessFile(installation, "r");
byte[] bytes = new byte[(int) f.length()];
f.readFully(bytes);
f.close();
return new String(bytes);
}
private static void writeInstallationFile(final Context context,File installation) throws IOException {
FileOutputStream out = new FileOutputStream(installation);
StringBuffer buf=new StringBuffer();
buf.append(Settings.Secure.getString(context.getContentResolver(),Settings.Secure.ANDROID_ID));
buf.append("-");
buf.append(UUID.randomUUID().toString());
out.write(buf.toString().getBytes());
out.close();
}
}
주의 !!!! 문서에 따르면 기기에서 초기화가 수행되면 'ANDROID_ID'값이 변경 될 수 있습니다. – breceivemail
간단한 코드 은 안드로이드 장치의 고유 ID를 얻을 수 있습니다 : (이것은 또한 정제에서 작동합니다.)
String deviceId = Secure.getString(MainActivity.this.getContentResolver(),Secure.ANDROID_ID);
Log.d("Device ID",deviceId);
때때로 null 인 것으로 알려져 있습니다. –
주의 !!!! 문서에 따르면 기기에서 초기화가 수행되면 'ANDROID_ID'값이 변경 될 수 있습니다. – breceivemail
또 다른 가능성 :
final TelephonyManager tm = (TelephonyManager) c
.getSystemService(Context.TELEPHONY_SERVICE);
Log.w("ID", tm.getDeviceId());
관련 질문은 well-w ritten 대답 : http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id/2853253#2853253 – jbenowitz
인용구 : "텔레포니 기반 ID는 태블릿 기기에는 없습니다. neh ? " –
그것은 유일하게 ... – Trikaldarshi