好久没写了,有些东西做过都快忘了,赶紧记一下。

现在来实现一个简单的相机程序。

原文地址http://www.cnblogs.com/rossoneri/p/4246134.html

当然需要的话可以直接调用系统的camera程序,但自己实现会使用更自由。

呐,既然要用实现相机,那就需要先了解一下调用camera的类android.hardware.camera

android.hardware.Camera

The Camera class is used to set image capture settings, start/stop preview, snap pictures, and retrieve frames for encoding for video. This class is a client for the Camera service, which manages the actual camera hardware.

To access the device camera, you must declare the android.Manifest.permission.CAMERA permission in your Android Manifest. Also be sure to include the <uses-feature> manifest element to declare camera features used by your application. For example, if you use the camera and auto-focus feature, your Manifest should include the following:

 <uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
To take pictures with this class, use the following steps: Obtain an instance of Camera from open(int).
Get existing (default) settings with getParameters().
If necessary, modify the returned Camera.Parameters object and call setParameters(Camera.Parameters).
If desired, call setDisplayOrientation(int).
Important: Pass a fully initialized SurfaceHolder to setPreviewDisplay(SurfaceHolder). Without a surface, the camera will be unable to start the preview.
Important: Call startPreview() to start updating the preview surface. Preview must be started before you can take a picture.
When you want, call takePicture(Camera.ShutterCallback, Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback) to capture a photo. Wait for the callbacks to provide the actual image data.
After taking a picture, preview display will have stopped. To take more photos, call startPreview() again first.
Call stopPreview() to stop updating the preview surface.
Important: Call release() to release the camera for use by other applications. Applications should release the camera immediately in android.app.Activity.onPause() (and re-open() it in android.app.Activity.onResume()).
To quickly switch to video recording mode, use these steps: Obtain and initialize a Camera and start preview as described above.
Call unlock() to allow the media process to access the camera.
Pass the camera to android.media.MediaRecorder.setCamera(Camera). See android.media.MediaRecorder information about video recording.
When finished recording, call reconnect() to re-acquire and re-lock the camera.
If desired, restart preview and take more photos or videos.
Call stopPreview() and release() as described above.
This class is not thread-safe, and is meant for use from one event thread. Most long-running operations (preview, focus, photo capture, etc) happen asynchronously and invoke callbacks as necessary. Callbacks will be invoked on the event thread open(int) was called from. This class's methods must never be called from multiple threads at once. Caution: Different Android-powered devices may have different hardware specifications, such as megapixel ratings and auto-focus capabilities. In order for your application to be compatible with more devices, you should not make assumptions about the device camera specifications.

camera类的文档简要说明

另外补充一下,实现android的video也是使用的Camera API,用到相关的类为Camera,SurfaceView,MediaRecorder,Intent(MediaStore.ACTION_IMAGE_CAPTURE, MediaStore.ACTION_VEDIO_CAPTURE)

好,根据camera的说明,在开始编写程序之前需要确认manifest中添加关于使用摄像设备的适当的权限声明,如果使用camera API必须加上下段说明:

<uses-permission android:name="android.permission.CAMERA" />

当然,程序也需要声明使用camera的特性:

<uses-feature android:name="android.hardware.camera" />
我就不翻译了,应该不难懂
<uses-feature android:name="android.hardware.camera" />
The application uses the device's camera. If the device supports multiple cameras, the application uses the camera that facing away from the screen. <uses-feature android:name="android.hardware.camera.autofocus" />
Subfeature. The application uses the device camera's autofocus capability. <uses-feature android:name="android.hardware.camera.flash" />
Subfeature. The application uses the device camera's flash. <uses-feature android:name="android.hardware.camera.front" />
Subfeature. The application uses a front-facing camera on the device. <uses-feature android:name="android.hardware.camera.any" />
The application uses at least one camera facing in any direction, or an external camera device if one is connected. Use this in preference to android.hardware.camera if a back-facing camera is not required.

camera的feature list

如果需要其他特性,在列表里选择性添加就好,比如一会儿我还需要自动对焦就要添加相关代码到manifest。添加特性代码就是为了防止你的程序被安装到没有摄像头或者不支持你要的功能的设备上去(prevent your application from being installed to devices that do not include a camera or do not support the camera features you specify. )

如果你的程序能通过适当的操作使用camera或一些特性,但并不特别需要它,可以增加required属性为false:

<uses-feature android:name="android.hardware.camera" android:required="false" />

Ok,前面说的有点多,下面说下使用camera的流程:

  • 整体流程
  1. 检测camera的存在并访问camera
  2. 继承SurfaceView并添加SurfaceHolder接口以显示预览画面
  3. 为预览画面添加你需要的布局和控件
  4. 增加对拍照事件的监听
  5. 使用拍照功能并保存照片
  6. 最后要释放camera
  • 流程细节
  1. 通过open(int)方法获取camera的实例,int为camera的id
  2. 使用getParameters()获取相机当前的设置,包括预览尺寸,拍照尺寸等等参数
  3. 如果修改了相关设置,调用setParameters(Camera.Parameters)将更改的信息重新生效
  4. 有需要的话使用setDisplayOrientation(int)来改变预览画面的方向
  5. 使用setPreviewDisplay(SurfaceHolder)传递一个完整初始化的SurfaceHolder,没有surface,就没法启动预览画面
  6. 在拍照之前先调用startPreview()来更新预览画面
  7. 调用takePicture(Camera.ShutterCallback, Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)进行拍照,在回调函数中获得照片对象并做处理
  8. 预览画面会在拍照后关闭,如果还需要拍照,记得先startPreview()
  9. 用stopPreview()来关闭预览画面
  10. camera使用之后一定要调用release()释放掉

下面跟着流程,开始编码

先在主界面添加一个按钮,用来打开相机,效果如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.demo_camera.MainActivity" > <Button
android:id="@+id/main_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/main_btn_open_camera" /> <include
android:id="@+id/camera_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/view_camera"
android:visibility="gone" /> </RelativeLayout>

activity_main.xml

设计拍照界面,一个surfaceview用来显示预览画面,两个button进行拍照和返回

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent" > <SurfaceView
android:id="@+id/cameraSurfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" /> <RelativeLayout
android:id="@+id/cameraButtonLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="horizontal" > <Button
android:id="@+id/cameraTakePicCancle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="@color/RoyalBlue"
android:text="@string/camera_btn_back" /> <Button
android:id="@+id/cameraTakePic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@id/cameraTakePicCancle"
android:layout_toStartOf="@id/cameraTakePicCancle"
android:background="@color/RoyalBlue"
android:text="@string/camera_btn_takephoto" />
</RelativeLayout> </FrameLayout>

view_camera.xml

编写camera操作的代码,增加了自动对焦,分辨前后摄像头等内容,为了代码看起来连贯,具体说明放在注释里

 package com.example.demo_camera;

 import java.util.List;

 import android.app.Activity;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Size;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button; public class CameraView {
// Private Constants /////////////////////////////////////////////////////// // Public Variables //////////////////////////////////////////////////////// // Member Variables ////////////////////////////////////////////////////////
private ViewGroup mView;
private Activity mActivity; private Button mBtnTakePhoto;
private Button mBtnBack;
private SurfaceView mSurfaceView; private Camera mCamera;
private Camera.Parameters mParameters;
private CameraInfo mCameraInfo; private int mDegree;
private int mScreenWidth;
private int mScreenHeight; // Constructors ////////////////////////////////////////////////////////////
public CameraView(Activity mActivity, ViewGroup mView) {
this.mActivity = mActivity;
this.mView = mView;
initCameraView();
initCameraEvent();
} // Class Methods /////////////////////////////////////////////////////////// // Private Methods /////////////////////////////////////////////////////////
private void initCameraView() {
mBtnTakePhoto = (Button) mView.findViewById(R.id.cameraTakePic);
mBtnBack = (Button) mView.findViewById(R.id.cameraTakePicCancle);
mSurfaceView = (SurfaceView) mView.findViewById(R.id.cameraSurfaceView); } private void initCameraEvent() { mSurfaceView.getHolder().setKeepScreenOn(true);// 屏幕常亮
mSurfaceView.getHolder().addCallback(new SurfaceCallback());// 为surfaceHolder添加回调
mSurfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT); mBtnTakePhoto.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
// if (mCamera != null) {
}
}); mBtnBack.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub }
});
} private final class SurfaceCallback implements SurfaceHolder.Callback { // 回调中包含三个重写方法,看方法名即可知道是干什么的 @Override
public void surfaceCreated(SurfaceHolder holder) { // 创建预览画面处理
// TODO Auto-generated method stub
int nNum = Camera.getNumberOfCameras(); // 根据摄像头的id找前后摄像头
if (nNum == 0) {
// 没有摄像头
return;
} for (int i = 0; i < nNum; i++) {
CameraInfo info = new CameraInfo(); // camera information 对象
Camera.getCameraInfo(i, info);// 获取information
if (info.facing == CameraInfo.CAMERA_FACING_BACK) { // 后摄像头
startPreview(info, i, holder); // 设置preview的显示属性
return;
}
} } @Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) { // 预览画面有变化时进行如下处理
// TODO Auto-generated method stub
if (mCamera == null) {
return;
} mCamera.autoFocus(new AutoFocusCallback() { // 增加自动对焦
@Override
public void onAutoFocus(boolean success, Camera camera) {
// TODO Auto-generated method stub
if (success) { // 如果自动对焦成功
mCamera.cancelAutoFocus(); // 关闭自动对焦,下次有变化时再重新打开自动对焦,这句不能少
}
}
});
} @Override
public void surfaceDestroyed(SurfaceHolder holder) { // surfaceView关闭处理以下方法
// TODO Auto-generated method stub
if (mCamera != null) {
mCamera.stopPreview();
mCamera.release(); // 释放照相机 不能少
mCamera = null;
mCameraInfo = null;
}
} } private Size getOptimalSize(int nDisplayWidth, int nDisplayHeight,
List<Size> sizes, double targetRatio) { // 这里是我的一个计算显示尺寸的方法,可以自己去设计
final double ASPECT_TOLERANCE = 0.001;
if (sizes == null)
return null; Size optimalSize = null;
double minDiff = Double.MAX_VALUE; int targetHeight = Math.min(nDisplayWidth, nDisplayHeight);
for (Size size : sizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;
} // Public Methods //////////////////////////////////////////////////////////
public void show() {
mView.setVisibility(View.VISIBLE);
mSurfaceView.setVisibility(View.VISIBLE); //
} public void hideCamera() {
mView.setVisibility(View.GONE);
mSurfaceView.setVisibility(View.GONE); //
} public final ViewGroup getViewGroup() {
return mView;
} public void initScreenSize(int nWidth, int nHeight) { // 设置屏幕的宽与高
ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams();
lp.width = nWidth;
lp.height = nHeight;
mSurfaceView.setLayoutParams(lp); mScreenWidth = nWidth;
mScreenHeight = nHeight;
} public void startPreview(CameraInfo info, int cameraId, SurfaceHolder holder) {// 在回调中调用设置预览的属性
try { mCameraInfo = info; mCamera = Camera.open(cameraId); mCamera.setPreviewDisplay(holder); // 设置用于显示拍照影像的SurfaceHolder对象
mCamera.setDisplayOrientation(90); // 设置显示的方向,这里手机是竖直为正向90度,可以自己写个方法来根据屏幕旋转情况获取到相应的角度 {
mParameters = mCamera.getParameters(); // PictureSize 获取支持显示的尺寸 因为支持的显示尺寸是和设备有关,所以需要获取设备支持的尺寸列表
// 另外因为是预览画面是全屏显示,所以显示效果也和屏幕的分辨率也有关系,为了最好的适应屏幕,建议选取
// 与屏幕最接近的宽高比的尺寸
List<Size> listPictureSizes = mParameters
.getSupportedPictureSizes(); Size sizeOptimalPicture = getOptimalSize(mScreenWidth,
mScreenHeight, listPictureSizes, (double) mScreenWidth
/ mScreenHeight);
mParameters.setPictureSize(sizeOptimalPicture.width,
sizeOptimalPicture.height); // PreviewSize
List<Camera.Size> ListPreviewSizes = mParameters
.getSupportedPreviewSizes(); Size sizeOptimalPreview = getOptimalSize(
sizeOptimalPicture.width, sizeOptimalPicture.height,
ListPreviewSizes, (double) sizeOptimalPicture.width
/ sizeOptimalPicture.height);
mParameters.setPreviewSize(sizeOptimalPreview.width,
sizeOptimalPreview.height); // 这里就是有的设备不支持Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE连续自动对焦这个字段,所以做个判断
List<String> lstFocusModels = mParameters
.getSupportedFocusModes();
for (String str : lstFocusModels) {
if (str.equals(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
mParameters
.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
break;
}
} mCamera.setParameters(mParameters);
} mCamera.startPreview(); // 开始预览 } catch (Exception e) {
e.printStackTrace();
}
}
}

CameraView.java

在MainActivity中添加下面主要代码

 package com.example.demo_camera;

 import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button; public class MainActivity extends Activity { Button mBtnCamera;
ViewGroup mVgCamera;
CameraView mCameraView; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // 全屏显示要隐藏标题栏状态栏
// hide title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
// hide status bar
int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Window window = this.getWindow();
window.setFlags(flag, flag); setContentView(R.layout.activity_main); mBtnCamera = (Button) findViewById(R.id.main_btn);
mVgCamera = (ViewGroup) findViewById(R.id.camera_layout);
mCameraView = new CameraView(this, mVgCamera); mBtnCamera.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
mBtnCamera.setVisibility(View.GONE);
mVgCamera.setVisibility(View.VISIBLE); setCameraSize(); }
});
} private void setCameraSize() { ViewGroup.LayoutParams params = mCameraView.getViewGroup()
.getLayoutParams();
DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);// 获得屏幕尺寸
params.width = dm.widthPixels;
params.height = dm.heightPixels; mCameraView.getViewGroup().setLayoutParams(params);
mCameraView.initScreenSize(params.width, params.height);
mCameraView.show();
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

MainActivity.java

在Manifest加入:

<uses-permission android:name="android.permission.CAMERA" />

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

最后一些资源文件string和color

<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">Demo_camera</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="camera_btn_back">Back</string>
<string name="camera_btn_takephoto">TakePic</string>
<string name="main_btn_open_camera">Open Camera</string> <color name="RoyalBlue">#4169E1</color>
</resources>

strings.xml

经过以上步骤,我们的设备就可以用摄像头进行预览了,预览时随意移动设备还可以自动对焦,效果如下图:

不过,这个是用DDMS截的图,如果是拍照,实际画面尺寸会与看到的稍有差别,原因在代码里也有写。

关于拍照takePicture(Camera.ShutterCallback, Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)的使用也很简单,在回调PictureCallback中重写public void onPictureTaken(byte[] data, Camera camera) {}方法,data就是图片数据,用bitmapfactory来decode一下,再处理一下显示的旋转方向与尺寸就ok了,这部分代码有空再补吧。

好了,又复习一遍这个过程发现还是蛮简单的。多看看官方的文档就好。ok,收工睡觉。

参考资料:

如何实现android手机摄像头的的自动对焦

android sdk docs


Feb.2nd

快放假了,年底略忙,项目需要年前赶个版本出来。

把上次的拍照过程补一下:

主要是拍照的回调方法,也就对拍照得到的数据按自己的需求处理一下,简单地decode成Bitmap就可以,然后加你想要的动画,另外加一些滤镜啊什么的效果,也就是一些数字图像处理算法,这个不在拍照范畴之内。下面的方法我仅仅对照片方向做了处理,然后缩放0.8倍在主界面显示(懒得再写个view放照片了,就用imageview显示,为了有点差别就缩小图片了

    private final class MyPictureCallback implements PictureCallback {

        @Override
public void onPictureTaken(byte[] data, Camera camera) {
// TODO Auto-generated method stub try { Bitmap bitmapRotate = BitmapFactory.decodeByteArray(data, 0, data.length); Bitmap mBmp = bitmapRotate;
int nDegree = getPictureDegree(mActivity, mCameraInfo);
if (nDegree != 0) {
Matrix matrix = new Matrix();
matrix.preRotate(nDegree);
mBmp = Bitmap.createBitmap(bitmapRotate, 0, 0, bitmapRotate.getWidth(), bitmapRotate.getHeight(), matrix, true);
} Bitmap bmpScale = Bitmap.createScaledBitmap(mBmp, (int) (mScreenWidth * 0.8), (int) (mScreenHeight * 0.8), true); if (mListener != null)
mListener.onTakePic(bmpScale);
closeCamera(); } catch (Exception e) {
e.printStackTrace();
}
}
}

写好回调后在takePhoto按钮事件下补充:

if (mCamera != null)
mCamera.takePicture(null, null, new MyPictureCallback());

在back按钮下补充:

takePicCancle();

cameraView最后补充代码:

  public void closeCamera() {
if (mCamera != null) {
mCamera.stopPreview();
mCamera.release(); // 释放照相机
mCamera = null;
mCameraInfo = null;
}
} public void takePicCancle() {
closeCamera();
// sigCameraCancle.emit();
if (mListener != null)
mListener.onBack();
}

为了让mainActivity能得到在camera里的按钮事件反馈,在cameraView中加两个接口:

public interface CameraViewListener {
public void onTakePic(Bitmap bmp);
public void onBack();
} private CameraViewListener mListener; public void setListener(CameraViewListener listener) {
mListener = listener;
}

然后在MainActivity添加以下代码:

implements CameraViewListener
implements CameraViewListener

mCameraView.setListener(this);

@Override
public void onTakePic(Bitmap bmp) {
// TODO Auto-generated method stub
mVgCamera.setVisibility(View.GONE);
mPhoto.setVisibility(View.VISIBLE);
mPhoto.setImageBitmap(bmp);
} @Override
public void onBack() {
// TODO Auto-generated method stub
mBtnCamera.setVisibility(View.VISIBLE); mVgCamera.setVisibility(View.GONE);
}

mPhoto是一个ImageView

<ImageView
android:id="@+id/main_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />

以上,按下拍照即可在主界面看到拍照得到的画面:

如果还需要完整代码请持续关注,我有空把Github整理好了会发出github的地址~~

[Android] 实现简单的相机程序的更多相关文章

  1. Android Camera 相机程序编写

    Android Camera 相机程序编写 要自己写一个相机应用直接使用相机硬件,首先应用需要一个权限设置,在AndroidManifest.xml中加上使用设备相机的权限: <uses-per ...

  2. android示例:一个简单的登陆程序

    最近写了个简单的登陆程序,有几点收获: 1.懂得如何在LinearLayout中嵌套LinearLayout,完善布局的行列: 2.用android:layout_weight控制控件的比重: 3.用 ...

  3. Android实现简单音乐播放器(startService和bindService后台运行程序)

    Android实现简单音乐播放器(MediaPlayer) 开发工具:Andorid Studio 1.3运行环境:Android 4.4 KitKat 工程内容 实现一个简单的音乐播放器,要求功能有 ...

  4. Android发展简单介绍

    Android一词的本义指“机器人”,同一时候也是Google于2007年11月5日宣布的基于Linux平台的开源手机操作系统的名称,该平台由操作系统.中间件.用户界面和应用软件组成,号称是首个为移动 ...

  5. Android 实现简单音乐播放器(二)

    在Android 实现简单音乐播放器(一)中,我介绍了MusicPlayer的页面设计. 现在,我简单总结一些功能实现过程中的要点和有趣的细节,结合MainActivity.java代码进行说明(写出 ...

  6. Android 实现简单音乐播放器(一)

    今天掐指一算,学习Android长达近两个月了,今天开始,对过去一段时间的学习收获以及遇到的疑难杂症做一些总结. 简单音乐播放器是我自己完成的第一个功能较为完整的APP,可以说是我的Android学习 ...

  7. Android课程---Android Studio简单设置

    Android Studio 简单设置 界面设置 默认的 Android Studio 为灰色界面,可以选择使用炫酷的黑色界面.Settings-->Appearance-->Theme, ...

  8. Android Studio 简单功能介绍

    Android Studio  建立系统工具包你用来生成,测试,运行您的应用程序和软件包.构建系统是独立于Android的工作室,所以你可以调用它的Android的工作室或从命令行.在你写你的应用程序 ...

  9. Android实现简单音乐播放器(MediaPlayer)

    Android实现简单音乐播放器(MediaPlayer) 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 工程内容 实现一个简单的音乐播放器,要求功能 ...

随机推荐

  1. JDK8 - Function介绍

    注:写这个文档只是为了方便加深记忆,加强理解,重点关注两个default方法中泛型[V]. JDK8作为一个还在维护阶段的长期版本,势必会在企业应用中占据相当大的市场份额,所以还是以JDK8作为例子的 ...

  2. spring cloud(服务注册中心及服务提供者——初学一)

    Eureka是Netflix开源的一款提供服务注册和发现的产品,它提供了完整的Service Registry和Service Discovery实现.也是springcloud体系中最重要最核心的组 ...

  3. ES6基础教程一 学习笔记

    一.变量的声明 1.var 声明全局变量 在ES6中var用来声明全局变量. 2.let 声明局部变量 3.const 声明常量 二.变量的解构赋值 //1.数组赋值 let [a,b,c]=[1,2 ...

  4. jmeter接口自动化部署jenkins教程

    首先,保证本地安装并部署了jenkins,jmeter,xslproc 我搭建的自动化测试框架是jmeter+jenkins+xslproc ---注意:原理是,jmeter自生成的报告jtl文件,通 ...

  5. Hadoop不适合处理实时数据的原因剖析

    1.概述 Hadoop已被公认为大数据分析领域无可争辩的王者,它专注与批处理.这种模型对许多情形(比如:为网页建立索引)已经足够,但还存在其他一些使用模型,它们需要来自高度动态的来源的实时信息.为了解 ...

  6. linux 文件句柄数查看命令

    当你的服务器在大并发达到极限时,就会报出“too many open files”. 查看线程占句柄数ulimit -a 输出如下:core file size (blocks, -c) 0data ...

  7. kafka 生产者基本操作

    kafka自带了一个在终端演示生产者发布消息的脚本--kafka-console-producer.sh 运行该脚本会启动一个进程,在运行该脚本时可以传递相应配置以覆盖默认配置. 参数-- -- pr ...

  8. 使用ssh-add命令添加ssh私钥时报错

    当使用ssh-add命令添加ssh私钥时,报如下错误: Could not open a connection to your authentication agent. 其实需要先执行如下命令: e ...

  9. 简易的命令行聊天室程序(Winsock,服务器&客户端)

    代码中使用WinSock2函数库,设计并实现了简单的聊天室功能.该程序为命令行程序.对于服务器和客户端,需要: 服务器:创建监听套接字,并按本地主机绑定:主线程监听并接受来自客户端的请求,并为该客户端 ...

  10. golang实现unicode码和中文之间的转换

    将中文转换为unicode码,使用golang中的strconv包中的QuoteToASCII直接进行转换,将unicode码转换为中文就比较麻烦一点,先对unicode编码按\u进行分割,然后使用s ...