i wish to write a plugin that will enable me to access hardware buttons of the phone while using the camera app. how would i go about doing this. or is it even possible.
Sorry, you can't generally do this. There are some keys that applications can respond to while in the background (specifically the media play/pause/etc buttons) but it is not generally possible to process key events while another app has focus.
Your best best is to check the Camera source but you might consider making your own app based on Camera.
Related
I wrote some code to play the shuttersound for Android using the camera2 API. The code is:
MediaActionSound mediaActionSound = new MediaActionSound();
mediaActionSound.play(MediaActionSound.SHUTTER_CLICK);
I've tested on more than ten devices. The problems are:
The actually play a different sound that the built-in camera.
Different devices actually play different sound. (It seems that the device manufacturer each has installed a different sound fine.)
There is some information about this file:
/system/media/audio/ui/camera_click.ogg
... but I'm not sure if this is the sound file used. And if so, why do they all sound different and not the same as the built-in camera.
The solution I'm seeking:
Either:
Play exactly the same sound as with the built-in camera. How do I do this?
or
Install a custom sound file into my app and play this same sound across all devices. (However, this method is secondarily preferred because we have to find a custom sound file.)
Please advise.
If the default camera app has its own shutter sound, it's unlikely you can get to it - it's likely either baked into the app APK, or some custom addition to that OEM's set of device sounds that isn't visible to non-system apps.
The main reason to use MediaActionSound to be compliant with the expectation in some countries that camera shutter sounds are not silenceable. MediaActionSound will still play a shutter sound even on a fully-silenced device in such countries, without the developer having to worry about it.
Otherwise, you could just play whatever sound you want on shutter press, if complying with the shutter sound enforcement isn't critical - or you can use your own sound when shutter sound muting isn't enforced (you can check via canDisableShutterSound), and fall back to MediaActionSound in places where shutter sound shouldn't be silenced.
It rely on your decision.
If you want to make your app's brand, just use the one you like or treat the user with their familiar sound. Your don't have to complicate it
I began creating an app that will run in the background and globally repurposes the play/pause/forward/backward buttons to change the volume which is intended to apply to any media player.
Example: While streaming media in Pandora or Youtube, pressing pause will
lower the volume then activate pause and pressing play will increase the volume then activate play.
I find that onMediaButtonEvent() will give me a similar effect except that this is localized to only within the app it is written in and applies to only physical hardware play/pause/forward/backward buttons.
Also, I can use onClick() which allows me to decide what happens when a play/pause/forward/backward button is pressed but this is limited to within the app.
Can anyone offer any insight on if there is another function, a work around or if this is even possible? Maybe i am looking in the wrong direction and there is something that needs to be modified in the kernel which is out of bounds.
I'm working on an application that needs to distinguish between physical touchscreen (hardware) touches and software simulated touches invoked by other application. Is there any way to do this without root access?
More info: I will be using this to detect if someone is using auto-clicker (auto-tapper?) software on their device to imitate activity in my application.
Bump: Still researching for an answer, I can't find any clear explanation online. Can anyone help?
No. Apps like BotMaker fake taps (that's why they require root, to be able to "inject" these fake taps) but it there's no concept of genuine vs fake taps in the Android so these injected will look equally genuine as any other tap to the apps.
Is it possible to capture the entire screen from Android application code? I'm developing an application like VNC for Android platform.
Regards
I think that depends on what you are trying to capture. I'm sure you can use Moss's method to create a screenshot from your own application - that is, something you render yourself.
As I understand it however, capturing from other views, apps, etc. is designed to be impossible for security reasons. This is to avoid apps being able to take screen shots from other apps, which would make it easy to steal sensitive data.
yes it is. You just need to create a canvas and assign it a Bitmap, then draw to that canvas instead of the canvas you use in your onDraw method and save the bitmap on the SDcard for example.
Just to renind you that this method will work if you handle the drawing, so you should use a custom home screen for it to capture wether you want. (just get the default android home screen :D).
I don't have personal experience with it, but this open source project sounds like it might either solve your problem, or provide you clues as to which API to use:
http://sourceforge.net/projects/ashot/
Screen capturing tool for Android
handsets connected via USB to a
desktop/laptop. It is great for
fullscreen presentations, product
demos, automatic screen recording, or
just a single screenshot. Without
root.
I know this in general is beyond the scope of SO, but I am looking for some basic yes/no info to see if it is even feasible to proceed... I am thinking about building and Android 'note-taking/annotation' app that runs 'over' other installed Android apps, such as the web browser for example.
Essentially, while the user is browsing, my app would be running in the bg as a service, and then they could activate it which would then essentially intercept user inputs and translate those on a transparent canvas over the web browser into lines, shapes, etc. The user could then take a screen-cap of their marking with the underlying web page, which would be stored to the sd card.
This is a very good idea and a great question, but sadly, I do not believe it is possible.
The way Android is designed only one Activity can have focus at a time, while a Service could run in the background, the user would not be able to interact with it. The user can only interact with the currently active Activity.
Again, love the idea, but it is sadly not supported.
You might be able to achieve this with the WindowManager service. You can then use that to call addView() with a view of type TYPE_SYSTEM_ALERT, or possibly TYPE_SYSTEM_OVERLAY (but see the notes in the documentation about taking input focus).
I haven't tried it myself, but I've seen several apps (often dictionary apps that translate whatever words you tap on) that do overlays, and they always seem to require the SYSTEM_ALERT_WINDOW permission.