Detailed description of the Android programming environment construction process

Source: Internet
Author: User

Next, let's take a look at how to use this interface in the camera application. First, let's take a look at the onCreate method in the Android programming environment. After reading this article, you will certainly have a lot of GAINS, I hope this article will teach you more things.

The former smartphone has many powerful functions, such as cameras, GPS, and wireless Internet access. Now is the time for us to fully use these functions. In this article, we will learn how to take photos of Google Android cameras in the simplest way in the Google Android programming environment.

 
  1. super.onCreate(icicle);  
  2.  
  3. getWindow().setFormat(PixelFormat.TRANSLUCENT);  
  4.  
  5. requestWindowFeature(Window.FEATURE_NO_TITLE);  
  6.  
  7. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
  8.  
  9. WindowManager.LayoutParams.FLAG_FULLSCREEN);  
  10.  
  11. setContentView(R.layout.camera);  
  12.  
  13. mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);  
  14.  
  15. mSurfaceHolder = mSurfaceView.getHolder();  
  16.  
  17. mSurfaceHolder.addCallback(this);  
  18.  
  19. mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);  
  20.  
  21. } 

In this example, we need to use two files: Layout files and Activity files. A few days ago, the new version of the Android programming environment (codenamed cupcake) was released, with many security improvements. One of them is related to camera permission control. Before that, you can create an app that allows you to take photos without the user's permission. Now this problem has been fixed. If you want to use a camera in your application, add the following code to AndroidManifest. xml:

 
  1. super.onCreate(icicle);  
  2.  
  3. getWindow().setFormat(PixelFormat.TRANSLUCENT);  
  4.  
  5. requestWindowFeature(Window.FEATURE_NO_TITLE);  
  6.  
  7. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
  8.  
  9. WindowManager.LayoutParams.FLAG_FULLSCREEN);  
  10.  
  11. setContentView(R.layout.camera);  
  12.  
  13. mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);  
  14.  
  15. mSurfaceHolder = mSurfaceView.getHolder();  
  16.  
  17. mSurfaceHolder.addCallback(this);  
  18.  
  19. mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);  
  20.  
  21. } 

This is the basis of the development work, that is, how many auxiliary elements we want to add to the application, such as camera function buttons. In this article, we adopt the simplest method. Apart from taking photos, there is no additional camera function. Next, let's take a look at the layout file camera_surface.xml used in this example ".

Tip: Remember not to use uppercase letters in the resource file name. If you name the file "CameraSurface. xml", it will cause unnecessary trouble. This layout is very simple. There is only one LinearLayout view group, and there is only one SurfaceView under it, that is, our camera screen.

This method allows the camera to prepare for taking a photo, set its parameters, and start previewing the screen in the Android programming environment. I used a "semaphore" parameter to prevent conflict: When mPreviewRunning is true, it means that the camera is active and not disabled, so we can use it.

In this way, we stop the camera and release related resources. As you can see, here we set mPreviewRunning to false. To prevent conflicts in the surfaceChanged method. Why? This means that we have disabled the camera, and we cannot set its parameters or start image preview in the camera.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.