Problem 3: photos can be stored, but their names are incorrect.
File: // mnt/sdcard/123 1.jpg, because the fromFile method of URI replaces spaces in the path with "% 20.
In fact, this is not a problem for most mobile phones. when parsing the storage path, the mobile phone will replace "% 20" with a space. In this way, the final photo name is the name we specified at the beginning: 123 bytes. We can find the photo in the path "file: // mnt/sdcard/123 1.jpg!
Summary:
(1) Use intent (data) in onActivityResult to make a short judgment.
(2) When specifying the photo path, check whether all the folders in the path exist. If no folder exists, create a folder and then call the camera to take the photo.
(3) When you specify the photo storage path, do not include spaces or other special symbols in the photo name.
2. Call the mobile phone Camera through the open method of Camera2.1 continuous auto focus crash
Cause: the first focus is not over, and the application layer initiates the second focus, causing the focus to fail.
Solution 1: Pass in AutoFocusCallback;
Solution 2: delayed operations;
Solution 3: exception capture.
2.2 incorrect judgment on the number of cameras
Symptom: When we use Camera. the getNumberOfCameras () method returns inaccurate results when detecting the number of cameras. If we try to open a non-existent Camera, an exception is thrown. This also reminds us to add exception protection when enabling the Camera.
Representative Models: Lenovo 278 T, codu 8022
2.3 flashlight judgment
We often use the following two methods to determine whether a mobile phone has a flashlight:
Method 1: Use the getSupportedFlashModes method;
Method 2: Use PackageManager to determine whether the flashlight is supported.
Method 1: 3.7% of the machine results are incorrect, and it is impossible to accurately determine whether the mobile phone has a flashlight. The main brands include codu, Tianyu, Lenovo, and Samsung. Method 2: 9.7% of the machine results are incorrect. The main brands include VIVO, gionee, cool, Tianyan, duowei, and Samsung.
We recommend that you use these two methods when determining whether your phone has a flashlight. The probability of an error will be greatly reduced.
2.4 switching between the always-on and other statuses
The precondition is that the flashlight is set to always on (Parameters. FLASH_MODE_TORCH), and the flashlight is always on. In this case, after setting the flashlight mode to Parameters. FLASH_MODE_AUTO, the flashlight remains on normally. This model accounts for about 12% of the popular models. In this case, we need to first set the flashlight mode to Parameters. FLASH_MODE_OFF and then set other modes.
2.5 After the release of Camera, the flash still shines
Now that this is enabled, we have to take care of it. To be honest, this problem was not my consideration in the past, because Camera will be released when the Activity is destroyed or paused when we use Camera. At this time, no matter what the flash is, it will be turned off with the release of Camera. It was not until I met OPPO R815T that my world view had changed. If the flash was set to always bright, even if the Camera flash was released, it was still steady.
And because Camera has been released, you can no longer turn off the flashlight. Close the App and uninstall the App. You can still turn off the battery ..... therefore, if your program has an operation to set the flashlight to always on, we recommend that you set the flashlight to off before releasing Camera (Parameters. FLASH_MODE_OFF) status.
2.6 alternative situations of CameraInfo
The official documentation provides examples of how to adjust the camera preview angle:
In this example, CameraInfo is very important. The final angle calculation is based on the orientation Value in CameraInfo. Therefore, if this value is inaccurate, our angle may be incorrect.
The orientation Value of CameraInfo obtained by VIVO V1 is 90 for the first time, while mCamera = Camera is executed. open (); then you can get the orientation Value of CameraInfo to 0, and get 0 in the future, unless you restart your mobile phone.
No matter which app on the mobile phone, after one Camera. open () is executed, the orientation of obtaining CameraInfo in all other programs is 0.
The camera that comes with the mobile phone can use the decompilation System camera, and it turns out that the system camera has not corrected the angle as shown in the official example.
Solution:
1. Follow the camera of the mobile phone system;
2. The orientation value of the mobile phone CameraInfo is set to 90.
3. Dual-cardThe basic solution to dual-card problems:
1. inference: the built-in system apps of mobile phones can use these functions normally, so there must be vendor-defined APIs to implement these functions;
2. decompilation: Framework, system App, and system database;
3. Positioning: TelephoneManager extension, SMSManager extension, telephone service extension, SMS service extension, and database field extension.
Iv. UI adaptationSpeaking of UI adaptation, it is a headache. The following figure shows the work of a product for UI adaptation. It can be seen that it is quite tedious.
In addition to resolution adaptation, sometimes a label in the layout file may cause some problems. Let's take a look at the following layout code:
Correct results:
Error result:
This is because the layout_marginTo label is used in FrameLayout versions earlier than Android 3.0. gravity must be set to take effect.
How can this problem be solved? In the component that sets android: layout_marginTop, set android: layout_gravity = top.
5. More amazing 1. Vendor's abstract methodsIf you need to implement the InputConnection interface, pay attention to the following exception:
Decomcompiled the Framework of this mobile phone and found that the vendor added an abstract method named performYLPrivateCommand in the InputConnection interface.
2. distance sensor
2.1 different phone event. values [0] values are ever changing
To put it simply, there are several representative examples:
1. Some mobile phones are normal, and when they are close to 0, they are 1 (0, 1 );
2. Mobile phone numbers with a small personality will increase, such as (0,100), (3,100), (), and so on;
3. The number of 213 mobile phones is rather inexplicable. (1.001, 5.003), do you mean high accuracy?
2.2 The relationship between values and distance is inconsistent
Since we use a number to determine whether the current situation is in the near-ear state, is it necessary to say the size of this value? The number of mobile phones that I have seen is smaller than that of mobile phones that I have seen. However, there are several mental cell phones (100 million) that are close to each other and are larger than those close to each other. This is a pitfall, so developers should pay attention to it ~~!!
2.3 The Return Value of the getMaximumRange method is incorrect.
There is an API: SensorManager. getdefasensensor (Sensor. TYPE_PROXIMITY ). getMaximumRange (), the document explains that this should obtain the maximum range of changes in the sensor value. For example, if the value is 0 when it is near, the value is 1 when it is far away. Therefore, the value of getMaximumRange () should be 1, which will not affect our judgment. Here I am only referring to the API and our daily usage habits. If this is not the case, it will cause trouble for our programming.