- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作 android 语音助手应用程序...在后台运行服务以识别语音命令。当用户说“selfie”这个词时,我想在默认系统相机应用程序中拍照。我已经知道如何使用语音命令,但问题是我无法让相机应用程序拍照 ...
我尝试了一些方法但不会帮助
第一次我尝试模拟安卓相机按键事件
Intent intent1 = new Intent("android.intent.action.CAMERA_BUTTON");
intent1.putExtra("android.intent.extra.KEY_EVENT", new KeyEvent(0,
KeyEvent.KEYCODE_CAMERA));
sendOrderedBroadcast(intent1, null);
intent1 = new Intent("android.intent.action.CAMERA_BUTTON");
intent1.putExtra("android.intent.extra.KEY_EVENT", new KeyEvent(1,
KeyEvent.KEYCODE_CAMERA));
sendOrderedBroadcast(intent1, null);
这个打开相机但不会在没有物理相机键的手机中拍照
第二次我尝试注入(inject)按键事件“enter”……比如蓝牙遥控快门……
KeyEvent eventDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER);
KeyEvent eventUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER);
dispatchKeyEvent(eventDown);
dispatchKeyEvent(eventUp);
但是在这个问题中我遇到了两个问题,第一个是这个代码不能在服务中使用,第二个是不可能将事件注入(inject)到其他应用程序,因为只有系统应用程序可以做到这一点
现在的问题是我该如何解决这个问题? 有可能吗?我在网上读到一些关于 appium 可以做到这一点的东西,但它是在线的,我希望我的应用程序离线工作
请注意:添加相机权限和注入(inject)事件权限无济于事,我不想使用相机 api,因为我想在默认系统相机应用程序中拍照。
最佳答案
是的,有可能经过 2 天的调查,我找到了解决方案。
Requirement : Open system camera app and click pic.
第 1 步:
在 list 文件中添加相机权限:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
第 2 步: 创建一个扩展 AccessibilityService
的服务 <service
android:name=".AccessTest"
android:enabled="true"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility_service_config"/>
</service>
第 3 步:在需要时启动服务
Intent mailAccessabilityIntent = new Intent(getApplicationContext(), AccessTest.class);
startService(mailAccessabilityIntent);
第 4 步: 添加辅助功能文件。
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackAllMask"
android:accessibilityFlags="flagEnableAccessibilityVolume"
android:canRetrieveWindowContent="true"
android:notificationTimeout="100"
android:packageNames="com.google.android.GoogleCamera"
android:settingsActivity="com.mobiliya.cameraautoclick.MainActivity" />
第 5 步:在您要处理相机相关监听器的地方编写服务类。
public class AccessTest extends AccessibilityService {
private final static String TAG = "Yogesh";
@Override
public void onCreate() {
super.onCreate();
Log.d("Yogesh","I am started");
}
@Override
protected void onServiceConnected() {
super.onServiceConnected();
Log.d(TAG, "onServiceConnected");
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.d(TAG, "ACC::onAccessibilityEvent: " + event.getEventType());
//TYPE_WINDOW_STATE_CHANGED == 32
if (AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED == event
.getEventType()) {
AccessibilityNodeInfo nodeInfo = event.getSource();
if (nodeInfo == null) {
return;
}
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String x = takePictureIntent.resolveActivity(getPackageManager()).getPackageName();
Log.d("Yogesh","Package name " + x);
List<AccessibilityNodeInfo> list1 = nodeInfo.findAccessibilityNodeInfosByText("Switch to front camera");
for (AccessibilityNodeInfo node : list1) {
Log.i(TAG, "ACC::onAccessibilityEvent: click " + node);
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
final List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText("Take photo");
final android.os.Handler handler = new android.os.Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
for (AccessibilityNodeInfo node : list) {
Log.i(TAG, "ACC::onAccessibilityEvent: click " + node);
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
handler.postDelayed(this,5000);
}
},10000);
for (AccessibilityNodeInfo node : list) {
Log.i(TAG, "ACC::onAccessibilityEvent: click " + node);
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
Log.d(TAG,"Access " + getAllChildNodeText(nodeInfo).toString());
}
}
private List<CharSequence> getAllChildNodeText(AccessibilityNodeInfo infoCompat) {
List<CharSequence> contents = new ArrayList<>();
if (infoCompat == null)
return contents;
if (infoCompat.getContentDescription() != null) {
contents.add(infoCompat.getContentDescription().toString().isEmpty() ? "unlabelled" : infoCompat.getContentDescription());
} else if (infoCompat.getText() != null) {
contents.add(infoCompat.getText().toString().isEmpty() ? "unlabelled" : infoCompat.getText());
} else {
getTextInChildren(infoCompat, contents);
}
if (infoCompat.isClickable()) {
if (infoCompat.getClassName().toString().contains(Button.class.getSimpleName())) {
if (contents.size() == 0) {
contents.add("Unlabelled button");
} else {
contents.add("button");
}
}
contents.add("Double tap to activate");
}
return contents;
}
private void getTextInChildren(AccessibilityNodeInfo nodeInfoCompat, List<CharSequence> contents) {
if (nodeInfoCompat == null)
return;
if (!nodeInfoCompat.isScrollable()) {
if (nodeInfoCompat.getContentDescription() != null) {
contents.add(nodeInfoCompat.getContentDescription());
} else if (nodeInfoCompat.getText() != null) {
contents.add(nodeInfoCompat.getText());
}
if (nodeInfoCompat.getChildCount() > 0) {
for (int i = 0; i < nodeInfoCompat.getChildCount(); i++) {
if (nodeInfoCompat.getChild(i) != null) {
getTextInChildren(nodeInfoCompat.getChild(i), contents);
}
}
}
}
}
@Override
public void onInterrupt() {
}
}
这里 getAllChildNodeText() 返回所有可点击的文本按钮,Google 默认应用程序有 Take Photo
文本,因此您可以为此 View 执行操作。
为每 10 秒捕获一次图片添加了处理程序,以进一步说明。
如果您想跟踪多个摄像头应用程序,请删除下面的行并使用 Java 代码设置包更多详细信息请参阅 - Accessibility Service
android:packageNames="com.google.android.GoogleCamera"
我上传了工作示例 -> https://github.com/ycrathi/cameraautoclick
注意:在上面的 GitHub 存储库中有多个不需要的代码,我试过了。
This solution is not global for all app. You can find some famous app like google camera and find text and then perform click action package wise.
关于android - 在默认系统相机应用程序中模拟拍照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39597012/
所以我对 Cordova 还很陌生,现在我正在使用它来制作一个应用程序,我正在尝试拍照然后保存它。现在我还不能拍照。我所拥有的只是一个按钮,在相应的 javascript 文件中,按下按钮时会调用一个
我有完整的工作代码来拍照、裁剪、发送带有图像附件的电子邮件。 代码流程如下:拍张照片 > 找到并选择我们刚刚从图库中拍摄的照片> 裁剪它 > 通过电子邮件发送附件。 我想了解如何跳过整个“查找并选择我
我是编程新手,正在尝试使用板载摄像头硬件制作应用程序,我的目的是拍照;然后,当您单击“保存”时,该图片将出现在要编辑的新 Activity 中...我已经研究了几天如何最好地使用相机硬件...有人告诉
有没有一种方法可以使用 UIImagePickerController 中的叠加层来显示用户可能使用的方形图片,同时在某处有一个切换按钮可以即时切换? 目前 iOS 7 相机有这个功能,但是 UIIm
当我点击 GestureDetector 时,它会打开一个对话框,我可以在其中选择是要从图库中拍摄照片还是要自己制作照片 (the plugin)。但我的问题是当我点击对话框中的一个按钮时,对话框再次
我的一个页面上有一个 map 控件,我想拍一张照片并将其显示在不同的屏幕上。有谁知道我怎么能做到这一点? map 在 内. 最佳答案 您应该使用 WriteableBitmap 类的 Render
我一直在构建一个使用 Flurge 的 CameraKit 的项目,但我遇到了一个相当烦人的问题。其实我不知道怎么拍照。我有一个快门按钮,按下该按钮应该会激活 OnPicturetaken Liste
当我启动照片捕捉 Intent 时,返回给我的照片路径是:content://media/external/images/media/40209 但是当我查看我的设备时,照片路径应该类似于 [..]/
我结账Camera2Basic (谷歌样本) 我刚刚在类 Camera2BasicFragment 中更改了这个方法为了用前置摄像头拍照: private void setUpCameraOutp
在 fragment 中我想拍照但是我遇到了问题,我从来没有得到 onActivityResult 的回调 我的代码: private void dispatchTakePictureIntent(
当我使用 UIImagePicker 从相机拍照时,背景音乐(来自 ipod 应用程序、pandora 应用程序)停止。 Facebook 应用程序不会发生这种情况。有单独的代表来做这件事吗?请帮忙
我用这个方法拍了一张照片。 func convertImageFromCMSampleBufferRef(sampleBuffer:CMSampleBuffer) -> CIImage{ le
在我的 chrome 上,以下代码仅打开相机并立即崩溃,即显示黑屏。这段代码在 Firefox 上运行良好。为什么? http://jsfiddle.net/2mLb6cs2/ (function()
我正在尝试在我的 iOS 应用程序中实现 OpenCV。 CvVideoCamera 很棒,因为它有一个委托(delegate)方法,可以让我处理相机预览的每一帧,但我不知道如何提取一帧并将其保存为图
当我想使用相机拍照时,CameraSource 出现了一些问题。我想要的只是用我在 xml 文件上制作的按钮拍照并使用“CameraSource”拍照,因为我也在使用“TextRecognizer”。
可以禁用/删除此照片确认对话框: 我需要以某种方式跳过此对话框,但我仍想使用 Intent。我找到了这个 android: Take camera picture without "save" / "
我正在使用 FileProvider 在 Android Nougat 上拍照,这是我的代码 文件路径.xml: Java: String fileName =
将文件路径额外添加到图像捕获 Intent 会导致相机应用程序在 TF300t Android 平板电脑上出现故障,系统版本为 4.2.1。按“完成”按钮什么都不做——甚至不关闭相机应用程序 Acti
我正在构建一个将跟踪库存的网络内联网应用程序,我希望能够使用 iPad 的内置相机为每件元素拍照。这可能吗? 我已经使用应用对条形码做了类似的事情,但我还没有找到任何可以对照片做同样事情的东西。 最佳
我用这个方法拍了一张照片。 func convertImageFromCMSampleBufferRef(sampleBuffer:CMSampleBuffer) -> CIImage{ le
我是一名优秀的程序员,十分优秀!