Нужна помощь, чтобы понять, что этот код действительно выводит. Выводит ли uuid в файл? Я нашел его на http://android-developers.blogspot.com/2011/03/identifying-app-installations.htmlПонимание этого кода
public synchronized static String id(Context context) {
if (sID == null) {
File installation = new File(context.getFilesDir(), INSTALLATION);
try {
if (!installation.exists())
writeInstallationFile(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(File installation) throws IOException {
FileOutputStream out = new FileOutputStream(installation);
String id = UUID.randomUUID().toString();
out.write(id.getBytes());
out.close();
}
}
код, как именно он будет размещен в моем приложении.
package com.UUIID;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import android.util.Log;
import java.io.RandomAccessFile;
import java.util.UUID;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;
public class UUIDActivity extends Activity {
/** Called when the activity is first created. */
TextView text;
private static final String TAG = "Installation";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(TAG, "program started");
text = (TextView) findViewById(R.id.textfield);
}
class Installation {
private String sID = null;
private static final String INSTALLATION = "INSTALLATION";
public synchronized String id(Context context) {
if (sID == null) {
File installation = new File(context.getFilesDir(),
INSTALLATION);
try {
if (!installation.exists())
writeInstallationFile(installation);
Log.d(TAG, "Inside of installation If statement");
sID = readInstallationFile(installation);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return sID;
}
private String readInstallationFile(File installation)
throws IOException {
RandomAccessFile f = new RandomAccessFile(installation, "r");
byte[] bytes = new byte[(int) f.length()];
f.readFully(bytes);
Log.d(TAG, "Right before it calls f to close");
f.close();
return new String(bytes);
}
private void writeInstallationFile(File installation)
throws IOException {
FileOutputStream out = new FileOutputStream(installation);
String id = UUID.randomUUID().toString();
Log.d(TAG, "Right before the file gets written out.");
out.write(id.getBytes());
out.close();
}
}
}
Итак, я понимаю, что код записывает UUID в файл, если он никогда не был создан на телефоне. Я искал через свою SD-карту телефона, и я не вижу в нем конкретного файла с UUID. Однако есть одна папка, которая не читается, является ли UUID Private? от пользователя? –