I try to get IMEI on android device and i can do this on android 4.2 successfully
but my written code does not work on android 5 and later
how do get IMEI on android 5 in firemonkey?
Here is a code snippet which gets the Android device IMEI for you using the Android JNI :
uses
Androidapi.JNI.Telephony, Androidapi.JNI.Provider ,
Androidapi.JNIBridge, Androidapi.JNI.GraphicsContentViewText ,
Androidapi.JNI.JavaTypes,FMX.Helpers.Android;
event :
procedure TForm1.btnCapturarIMEIClick(Sender: TObject);
var
obj: JObject;
tm: JTelephonyManager;
IMEI: String;
begin
obj := SharedActivityContext.getSystemService(TJContext.JavaClass.TELEPHONY_SERVICE);
if obj <> nil then
begin
tm := TJTelephonyManager.Wrap( (obj as ILocalObject).GetObjectID );
if tm <> nil then
IMEI := JStringToString(tm.getDeviceId);
end;
if IMEI = '' then
IMEI := JStringToString(TJSettings_Secure.JavaClass.getString( SharedActivity.getContentResolver, TJSettings_Secure.JavaClass.ANDROID_ID));
ShowMessage('IMEI :' + #13 + IMEI);
end;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.