android 遠端視訊監控系統
阿新 • • 發佈:2019-02-17
基本過程是Android作為socket客戶端將採集到的每一幀影象資料傳送出去,PC作為伺服器接收並顯示每一幀影象實現遠端監控。圖片如下(後來PC端加了個拍照功能)。。。
(PS。剛學android和Java不久很多東西還不懂,高手若是知道哪些地方可以繼續優化的話還請多多指點下啊)
系統程式碼如下:
一、android手機客戶端
(1)AndroidManifest.xml檔案。新增camera和socket許可權,並設定了程式開始執行的activity、
- <?xmlversion="1.0"encoding="utf-8"?>
-
<
- package="org.wanghai.CameraTest"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdkandroid:minSdkVersion="15"/>
- <!-- 授予程式使用攝像頭的許可權 -->
-
<uses-permissionandroid:name="android.permission.CAMERA"
- <uses-featureandroid:name="android.hardware.camera"/>
- <uses-featureandroid:name="android.hardware.camera.autofocus"/>
- <uses-permissionandroid:name="android.permission.INTERNET"/>
-
<uses-permissionandroid:name="android.permission.KILL_BACKGROUND_PROCESSES"
- <uses-permissionandroid:name="android.permission.RESTART_PACKAGES"/>
- <application
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name">
- <activity
- android:name=".GetIP"
- android:screenOrientation="landscape"
- android:label="@string/app_name">
- <intent-filter>
- <actionandroid:name="android.intent.action.MAIN"/>
- <categoryandroid:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- </activity>
- <activity
- android:name=".CameraTest"
- android:screenOrientation="landscape"
- android:label="@string/app_name">
- </activity>
- </application>
- </manifest>
(2)main.xml 設定surfaceview用於攝像頭採集影象的預覽
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <SurfaceView
- android:id="@+id/sView"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:scaleType="fitCenter"/>
- </LinearLayout>
(3)login.xml 登入介面,用於輸入伺服器IP
- <?xmlversion="1.0"encoding="utf-8"?>
- <TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/loginForm"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TableRow>
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="IP:"
- android:textSize="10pt"
- />
- <!-- 輸入使用者名稱的文字框 -->
- <EditText
- android:id="@+id/ipedittext"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:digits="0123456789."
- android:hint="請填寫伺服器IP"
- android:selectAllOnFocus="true"
- />
- </TableRow>
- </TableLayout>
(4)GetIP.java 獲得伺服器IP後,通過Intent啟動CameraTest的activity,ip資訊通過Bundle傳遞
- publicclass GetIP extends Activity {
- String ipname = null;
- @Override
- publicvoid onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // 設定全屏
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.main);
- final Builder builder = new AlertDialog.Builder(this); //定義一個AlertDialog.Builder物件