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;