【发布时间】:2014-02-10 01:56:50
【问题描述】:
我发送以下意图来模拟硬件相机按钮按下。此代码在服务中运行。我第一次运行此代码(在随机屏幕中)时,它会按预期打开默认的相机应用程序。但是,如果我在相机应用程序中再次运行此代码,它不会像我预期的那样拍照。它只是重新加载相机应用程序。问题是:
我还需要做什么才能让默认相机应用拍照?(无需用户交互)。
long eventtime = SystemClock.uptimeMillis();
Intent downIntent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
KeyEvent downEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_CAMERA, 0);
downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
sendOrderedBroadcast(downIntent, "android.permission.CAMERA");
Intent upIntent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
KeyEvent upEvent = new KeyEvent(eventtime+100, eventtime+100,
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_CAMERA, 0);
upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
sendOrderedBroadcast(upIntent, "android.permission.CAMERA");
(我觉得这个权限真的没必要)
【问题讨论】:
标签: android button camera simulate