C/C++获取安卓手机IMEI编号demo
#include <stdlib.h>
#include <exception>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
try {
system("service call iphonesubinfo 1 >/sdcard/imei.txt");
ifstream imei_file("/sdcard/imei.txt");
ostringstream imei_file_out;
char buf;
while (imei_file_out && imei_file.get(buf)) {
imei_file_out.put(buf);
}
string imei_origin = imei_file_out.str();
cout << imei_origin << endl;
int indexes[] = {75, 77, 79, 81, 136, 138, 140, 142,
144, 146, 148, 150, 205, 207, 209};
std::string imei;
for (int i = 0; i < 15; i++) {
imei += imei_origin[indexes[i]];
}
std::cout << imei << std::endl;
system("rm /sdcard/imei.txt");
} catch (exception& e) {
cout << e.what();
exit(1);
}
return 0;
}