|
本帖最后由 fghydx 于 2016-5-11 16:04 编辑
写了个函数,想调用这个函数执行振动.但无论是在CallInUIThread中还是直接写,都会在 LJO := SharedActivity.getSystemService(TJActivity.JavaClass.VIBRATOR_SERVICE);这一句闪退Delphi 10 也闪退 乐视手机
procedure Vibrator(Long: integer);
var
LVibrator: JVibrator;
LJO: JObject;
begin
CallInUIThread(
procedure
begin
try
LJO := SharedActivity.getSystemService(TJActivity.JavaClass.VIBRATOR_SERVICE); //在执行这一句时闪退
if Assigned(LJO) then
begin
LVibrator := TJVibrator.Wrap((LJO as ILocalObject).GetObjectID);
if LVibrator.hasVibrator then
begin
LVibrator.vibrate(Long);
end
else
begin
ShowToast('你的手机不支持振动!', ShortToast);
end;
end;
except
ShowToast(Exception(ExceptObject).Message, TToastLength.ShortToast);
end;
end);
end;
LJO := SharedActivity.getSystemService(TJActivity.JavaClass.VIBRATOR_SERVICE); //这一句错了,应该是
LJO := SharedActivity.getSystemService(TJContext.JavaClass.VIBRATOR_SERVICE);
|
|