Android 11.0 修复Camera 使用闪光灯拍照后,查看图片时详细信息为“未使用闪光灯”状态

Posted 王睿丶

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 11.0 修复Camera 使用闪光灯拍照后,查看图片时详细信息为“未使用闪光灯”状态相关的知识,希望对你有一定的参考价值。

packages/apps/Camera2 / src/com/android/camera/ButtonManager.java

    // wangrui Get AppController as a global object, we need it in SettingsManager
++    public static  AppController appController;

 /**
     * Get a new global ButtonManager.
     */
    public ButtonManager(AppController app) 
        mAppController = app;
        // wangrui Get AppController as a global object, we need it in SettingsManager
++        appController = mAppController;

        Context context = app.getAndroidContext();
        sGcamIndex = context.getResources().getInteger(R.integer.camera_mode_gcam);

        mSettingsManager = app.getSettingsManager();
        mSettingsManager.addListener(this);
    

packages/apps/Camera2 / src/com/android/camera/CameraActivity.java

    // wangrui Get whether the current camera is front or back, 0-back shot 1-front shot
    public static int mCameraId = 0;
    // wangrui Get the global context, we will use it in ExifUtil
    public static Context myContext;

 @Override
    public String getCameraScope() 
        CameraId cameraId =  mCameraController.getCurrentCameraId();
        //wangrui Get whether the current camera is front or back, 0-back shot 1-front shot
++        try 
++            mCameraId = Integer.parseInt(cameraId.getValue());
++        catch (Exception e)
++            e.printStackTrace();
++        

        if(cameraId == null) 
            Log.e(TAG,  "Retrieving Camera Setting Scope with -1");
            return SettingsManager.getCameraSettingScope("-1");
        

        return SettingsManager.getCameraSettingScope(cameraId.getValue());
    

packages/apps/Camera2 / src/com/android/camera/settings/SettingsManager.java

++ import com.android.camera.ButtonManager;
++ import static android.content.Context.MODE_PRIVATE;

private OnSharedPreferenceChangeListener getSharedPreferenceListener(
            final OnSettingChangedListener listener) 
        return new OnSharedPreferenceChangeListener() 
            @Override
            public void onSharedPreferenceChanged(
                    SharedPreferences sharedPreferences, String key) 
                // wangrui Get the flash status and store the value in the database
++                if (ButtonManager.appController!= null)
++                    if (key.equals(Keys.KEY_FLASH_MODE))
++                        int index = SettingsManager.this.getIndexOfCurrentValue(ButtonManager.appController.getCameraScope(),
                                Keys.KEY_FLASH_MODE);
++                        SharedPreferences.Editor editor = mContext.getSharedPreferences("camera_flash_state",MODE_PRIVATE).edit();
++                        editor.putInt("state",index);
++                       editor.apply();
++                    
++                
                listener.onSettingChanged(SettingsManager.this, key);
            
        ;
    

packages/apps/Camera2 / src/com/android/camera/util/ExifUtil.java

++ import android.content.SharedPreferences;
++ import com.android.camera.CameraActivity;
++ import static android.content.Context.MODE_PRIVATE;

  private void addCaptureResultToExif(CaptureResultProxy result) 
  
++        // wangrui If the camera is switched to the front, then the flash must not be turned on
++        if (CameraActivity.mCameraId==1)
++            addExifTag(ExifInterface.TAG_FLASH, ExifInterface.Flash.DID_NOT_FIRE);
++        else  // wangrui Retrieve flash status from database Close-0, open-1, open-2
++            SharedPreferences pref = CameraActivity.myContext.getSharedPreferences("camera_flash_state",MODE_PRIVATE);
++            int index = pref.getInt("state",1);
++            switch (index)
++                case 0:
 ++                   addExifTag(ExifInterface.TAG_FLASH, ExifInterface.Flash.DID_NOT_FIRE);break;
++              case 1:
++                case 2:
++                    addExifTag(ExifInterface.TAG_FLASH, ExifInterface.Flash.FIRED);break;
++            
++        

//        // Flash mode
//        Integer flashMode = result.get(CaptureResult.FLASH_MODE);
//        if (flashMode == CaptureResult.FLASH_MODE_OFF) 
//            addExifTag(ExifInterface.TAG_FLASH, ExifInterface.Flash.DID_NOT_FIRE);
//         else 
//            addExifTag(ExifInterface.TAG_FLASH, ExifInterface.Flash.FIRED);
//        

我是王睿丶,加入我的Q群:901440630,欢迎一起讨论安卓技术!

以上是关于Android 11.0 修复Camera 使用闪光灯拍照后,查看图片时详细信息为“未使用闪光灯”状态的主要内容,如果未能解决你的问题,请参考以下文章

Android 11.0 修复Camera 启用后置摄像头在拍照界面下,白平衡按钮无法点击

Android 11.0 修复:Camera 拍照后,图片详情信息的分辨率和画质信息概率性丢失

Android 11.0 修复Camera预览照片时按键盘左右键,底部功能栏的焦点也同时变动

Android 11.0 Camera 默认分辨率90W像素

Android 11.0 根据Camera的YUYV和MJPG两种格式做特殊处理

Android 11.0 Camera 分辨率从高到低排列