im making android voice assistant app...that run service in background for recognizing the voice command . i want to take picture in default system camera app when the user say's the word "selfie".i already know how to work with voice command but the problem is i cant make the camera app take picture ...
i tried some way but wont helped
1st i tried to simulate android camera key event
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);
this one open camera but wont take picture in phone's without physical camera key
2nd i tried to inject key event "enter" ... like bluetooth remote shutter ...
KeyEvent eventDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER);
KeyEvent eventUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER);
dispatchKeyEvent(eventDown);
dispatchKeyEvent(eventUp);
but in this one i faced 2 problem 1st this code cant be use in service 2nd its impossible to inject event to other app since that only system app could do this
now the question is how can i fix this problem? is it possible or not? i read some thing on web that appium could do this but its online & i want my app working off line
note that : adding camera permission & inject event permission wont help and i don't want to use camera api because i want to take pic in default system camera app.
you can use 3rd-party "fake camera" apps such as:
Image2Camera Fake Camera by New Horizon Apps Fake Camera - donate version by Vaclav Balak
alternatively you can use:
ICS emulator - that supports camera
alternatively you can use:
In your AVD advanced settings, you should be able to set front and back cameras to Webcam() or Emulated
Yes, Its possible After 2 days investigation I find the solution.
Step 1:
Add Camera permission in manifest file:
Step 2: Create one service which extends AccessibilityService
Step 3: Start service when you required
Step 4: Add accessibility file.
Step 5: Write service class where you want to handle camera related listener.
Here getAllChildNodeText() return all text button which is clickable, Google default application have
Take Photo
text so for this view you can perform action.Added handler for capture pic every 10 seconds for more clarification.
If you want to track multiple camera app then remove below line and use Java code for set package more details See -Accessibility Service
I uploaded working example -> https://github.com/ycrathi/cameraautoclick
Note: In above GitHub repo have multiple unwanted code, which I tried.