特殊J服务对象,需要用 SharedActivityContext.getSystemService(TJContext.JavaClass.某服务); 的方式建立。
例如:
procedure TMainForm.Button1Click(Sender: TObject);
var
TM: JTelephonyManager;
var
TelephonyServiceNative: JObject;
begin
TelephonyServiceNative := SharedActivityContext.getSystemService(TJContext.JavaClass.TELEPHONY_SERVICE);
if Assigned(TelephonyServiceNative) then
TM := TJTelephonyManager.Wrap((TelephonyServiceNative as ILocalObject).GetObjectID);
try
Edit1.Text := JStringToString(TM.getLine1Number);
except
on E: Exception do
begin
ShowMessage('发生错误' + sLineBreak + E.Message);
end;
end;
end;