Android之解决远程拍照不打开activity用其它方式获取surfaceView

关键代码:

mSurfaceView = new SurfaceView(mContext);

mSurfaceHolder = mSurfaceView.getHolder();

mSurfaceHolder.setType(SurfaceHolder.SURFACETYPE_TYPE_PUSH_BUFFERS)//获取相机缓存数据m

mSurfaceHoler.addCallback(mSurfaceCallback);

mWindowManager = (WindowManager)this.getSystemService(Context.WINOW_SERVICE);

WindowManager.LayoutParams params = new WindowManager.LayoutParams(1,1,WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,0,PixelFormat.UNKNOWN);

mWindowManager.addView(mSurfaceView);

注意事项:

mWindowManager.addView(mSurfaceView);之后操作完成之后要记得
<pre name="code" class="html">mWindowManager.removeView(mSurfaceView);

<pre name="code" class="html">mSurfaceCallback = new SurfaceHoler.callBack(){
    public void surfaceCreated(SurfaceHoler holder){
       initCamera();
    }
};
(0)

相关推荐