It's possible by using WindowManager
in Android.
https://stackoverflow.com/a/10268650/3047840
I should say yes you need SurfaceView
to take a picture but it does not have to be tied to a certain xml layout. You can add it to the WindowManager
class which works even in the Service. So the WindowManager
here opens a 'window' for you to do any floating effect in Android.
Specifically,
You can add a SurfaceView
into the WindowManager
and set the parameters as following.
mPreview = new CameraPreview(this, mCamera, jpegCallback);
WindowManager wm = (WindowManager) this
.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSPARENT);
params.height = 1;
params.width = 1;
wm.addView(mPreview, params);
Android has this functionality while iOS doesn't. This is why you can have Facebook chathead active on the home screen in Android rather than iOS.
Show facebook like chat head from a broadcast receiver in android