Installtion ID : UUID 统计安装
2016-03-21 21:41
375 查看
public class Installation {
private static String sID = null;
private static final String INSTALLATION = "INSTALLATION";
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();
}
}
相关文章推荐
- apue- chapter 3 文件IO
- ACM程序设计选修课——1058: Lucky Sequence(思考)
- iOS工具种之16进制颜色转为UIColor
- MFC中关于UINT与USHORT
- UI进阶——XMPP即时通讯
- CROC 2016 - Elimination Round (Rated Unofficial Edition) E. Intellectual Inquiry 贪心 构造 dp
- Farey Sequence(欧拉函数)
- INSTALL_FAILED_UID_CHANGED解决办法
- 带大文件飞---威刚UE700-128G优盘速度测试
- 为什么Arduino UNO工作电压是5V,但是需要9V的电源适配器
- CF645E-Intellectual Inquiry 贪心
- iOS开发UI篇—ios应用数据存储方式(归档) :转发
- iOS UIImageView居中
- UITableView,UICollectionView和CoreData完美结合进行增删改操作,如何导入大量数据,如何利用NSEntityMigrationPol
- Selected collating sequence not supported by the operating system vc6.0报错
- Core Data Model Versioning and Data Migration Programming Guide
- Android开发优化之——对界面UI的优化(1)
- UITableView的区头(不可滑动)和表头之分
- c# hasvalue属性
- 机房收费系统遇到的问题(三) 那些细节