資源簡(jiǎn)介
Android 后臺(tái)Service 實(shí)現(xiàn)錄像,無(wú)頁(yè)面
代碼片段和文件信息
package?com.uiot.smarthome.server;/**
import?android.app.Notification;
import?android.app.Service;
import?android.content.Context;
import?android.content.Intent;
import?android.graphics.PixelFormat;
import?android.hardware.Camera;
import?android.media.CamcorderProfile;
import?android.media.MediaRecorder;
import?android.os.Environment;
import?android.os.IBinder;
import?android.support.annotation.Nullable;
import?android.text.format.DateFormat;
import?android.view.Gravity;
import?android.view.SurfaceHolder;
import?android.view.SurfaceView;
import?android.view.WindowManager;
import?java.util.Date;
/**
?*?@描述?(測(cè)試程序可實(shí)現(xiàn)后臺(tái)錄像)
?*?@date?2016/8/15?0015?8:28?
?*/
public?class?BackgroundVideoRecorder?extends?Service?implements?SurfaceHolder.Callback?{
????private?WindowManager?windowManager;
????private?SurfaceView?surfaceView;
????private?Camera?camera?=?null;
????private?MediaRecorder?mediaRecorder?=?null;
????@Override
????public?void?onCreate()?{
????????//?Start?foreground?service?to?avoid?unexpected?kill
????????Notification?notification?=?new?Notification.Builder(this)
????????????????.setContenttitle(“Background?Video?Recorder“)
????????????????.setContentText(““)
????????????????.setSmallIcon(R.drawable.button_selector)
????????????????.build();
????????startForeground(1234?notification);
????????//?Create?new?SurfaceView?set?its?size?to?1x1?move?it?to?the?top?left?corner?and?set?this?service?as?a?callback
????????windowManager?=?(WindowManager)?this.getSystemService(Context.WINDOW_SERVICE);
????????surfaceView?=?new?SurfaceView(this);
????????WindowManager.LayoutParams?layoutParams?=?new?WindowManager.LayoutParams(
????????????????1?1
????????????????WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY
????????????????WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
????????????????PixelFormat.TRANSLUCENT
????????);
//全屏顯示在最上圖層上
//????????final?WindowManager.LayoutParams?layoutParams?=?new?WindowManager.LayoutParams(
//????????????????WindowManager.LayoutParams.WRAP_CONTENT
//????????????????WindowManager.LayoutParams.W
評(píng)論
共有 條評(píng)論