In earlier versions of Android Sdk, what should I do if the getSupportedFlashModes and setFlashMode functions are not available?

Source: Internet
Author: User

When using Camera and SurfaceView for cameras, you will inevitably encounter the problem of setting the Camera flash. Before setting the Camera, you must first obtain the flash mode supported by the Camera and then set it. As I am developing in a lower version, the getSupportedFlashModes and setFlashMode functions provided by the system are not provided. What should I do? Refer to the following key code:

[Plain] private static final String KEY_FLASH_MODE = "flash-mode ";
Private static final String SUPPORTED_VALUES_SUFFIX = "-values ";
Private Camera. Parameters mParms;
 
Public List <String> getSupportedFlashModes (){
String str = mParms. get (KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX );
Return split (str );
}
 
Public void setFlashMode (String value ){
MParms. set (KEY_FLASH_MODE, value );
}
 
Private ArrayList <String> split (String str ){
If (str = null)
Return null;
 
StringTokenizer tokenizer = new StringTokenizer (str ,",");
 
ArrayList <String> substrings = new ArrayList <String> ();
 
While (tokenizer. hasMoreElements ()){
Substrings. add (tokenizer. nextToken ());
}
Return substrings;
}
Private static final String KEY_FLASH_MODE = "flash-mode ";
Private static final String SUPPORTED_VALUES_SUFFIX = "-values ";
Private Camera. Parameters mParms;

Public List <String> getSupportedFlashModes (){
String str = mParms. get (KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX );
Return split (str );
}

Public void setFlashMode (String value ){
MParms. set (KEY_FLASH_MODE, value );
}

Private ArrayList <String> split (String str ){
If (str = null)
Return null;

StringTokenizer tokenizer = new StringTokenizer (str ,",");

ArrayList <String> substrings = new ArrayList <String> ();

While (tokenizer. hasMoreElements ()){
Substrings. add (tokenizer. nextToken ());
}
Return substrings;
}

The above code is deducted from the source code in the later version of the official website. The get and set methods are mainly used for encapsulation. The main purpose of writing this article is to remind me that we often need to learn how to find new ideas, read the source code, and find a work und to solve the problem, instead of looking for answers all over the world blindly!

From the pure soul

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.