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