android4.2 camera icon

Android4.2 默认没有camera icon,解决办法:

 

由一下log 推出:

 

I/DisableCameraReceiver( 2989): noback camera

I/DisableCameraReceiver( 2989):disable all camera activities

 

Packages/apps/Camera/src/com/android/camera/DisableCameraReceiver.java

 

public class DisableCameraReceiverextends BroadcastReceiver {

   private static final String TAG = "DisableCameraReceiver";

   private static final boolean CHECK_BACK_CAMERA_ONLY = true;

   private static final String ACTIVITIES[] = {

       "com.android.camera.CameraLauncher",

   };

 

 

   @Override

   public void onReceive(Context context, Intent intent) {

       // Disable camera-related activities if there is no camera.

 

 

       boolean needCameraActivity =CHECK_BACK_CAMERA_ONLY ? hasBackCamera() : hasCamera();

   

    Log.i(TAG,"++++sam debug needCameraActivity: " + needCameraActivity);

    needCameraActivity = true;

 sam debug 0425

 

 

       if (!needCameraActivity) {

            Log.i(TAG, "disable all cameraactivities");

            for (int i = 0; i <ACTIVITIES.length; i++) {

                disableComponent(context,ACTIVITIES[i]);

            }

       }

 

 

       // Disable this receiver so it won't run again.

       disableComponent(context,"com.android.camera.DisableCameraReceiver");

   }

 

 

   private boolean hasCamera() {

       int n =android.hardware.Camera.getNumberOfCameras();

       Log.i(TAG, "number of camera: " + n);

       return (n > 0);

   }

 

 

   private boolean hasBackCamera() {

       int n = android.hardware.Camera.getNumberOfCameras();

       CameraInfo info = new CameraInfo();

       for (int i = 0; i < n; i++) {

            android.hardware.Camera.getCameraInfo(i,info);

            if (info.facing ==CameraInfo.CAMERA_FACING_BACK) {

                Log.i(TAG, "back camera found:" + i);

                return true;

            }

       }

       Log.i(TAG, "no back camera");

       return false;

   }

 

 

   private void disableComponent(Context context, String klass) {

       ComponentName name = new ComponentName(context, klass);

       PackageManager pm = context.getPackageManager();

 

 

 Log.d(TAG, "++++sam debug 111111111111111name :" + name.getPackageName());

 Log.d(TAG, "++++sam debug 111111111111111name1 :" + PackageManager.COMPONENT_ENABLED_STATE_DISABLED);

 Log.d(TAG, "++++sam debug 111111111111111name2 :" + PackageManager.DONT_KILL_APP);

 

 

       // We need the DONT_KILL_APP flag, otherwise we will be killed

       // immediately because we are in the same app.

       pm.setComponentEnabledSetting(name,

            PackageManager.COMPONENT_ENABLED_STATE_DISABLED,

            PackageManager.DONT_KILL_APP);

   }

}

 

 

 

 

2:frameworks/av/services/camera/libcameraservice/CameraService.cpp

 

void CameraService::onFirstRef()

{

   BnCameraService::onFirstRef();

 

 

   if (hw_get_module(CAMERA_HARDWARE_MODULE_ID,

                (const hw_module_t**)&mModule) < 0) {

       ALOGE("Could not load camera HAL module");

       mNumberOfCameras = 0;

   }

   else {

       mNumberOfCameras= mModule->get_number_of_cameras();

        if (mNumberOfCameras > MAX_CAMERAS){

            ALOGE("Number of cameras(%d)> MAX_CAMERAS(%d).",

                    mNumberOfCameras,MAX_CAMERAS);

            mNumberOfCameras = MAX_CAMERAS;

       }

       for (int i = 0; i < mNumberOfCameras; i++) {

            setCameraFree(i);

       }

   }

}

 

 

CameraService::~CameraService() {

   for (int i = 0; i < mNumberOfCameras; i++) {

       if (mBusy[i]) {

            ALOGE("camera %d is still inuse in destructor!", i);

       }

   }

 

 

   gCameraService = NULL;

}

 

 

int32_tCameraService::getNumberOfCameras() {

    return mNumberOfCameras;

}

 

 

3:hardware/imx/mx6/libcamera2/CameraModule.cpp

 

 

camera_module_t HAL_MODULE_INFO_SYM ={

   common: {

       tag: HARDWARE_MODULE_TAG,

       module_api_version: CAMERA_MODULE_API_VERSION_2_0,

       hal_api_version: HARDWARE_HAL_API_VERSION,

       id: CAMERA_HARDWARE_MODULE_ID,

       name: "Freescale CameraHal Module",

       author: "Freescale",

       methods: &camera_module_methods,

       dso: NULL,       /* removecompilation warnings */

       reserved: { 0 }, /* remove compilation warnings */

   },

   get_number_of_cameras: camera_get_number_of_cameras,

   get_camera_info: camera_get_camera_info,

};

 

 

 

 

 

 

int camera_get_number_of_cameras()

{

   int back_orient = 0,  front_orient= 0;

 

 

   if (gCameraNum == 0) {

       char name_back[CAMERA_SENSOR_LENGTH];

       char name_front[CAMERA_SENSOR_LENGTH];

       GetCameraPropery(name_back,

                         name_front,

                         &back_orient,

                         &front_orient);

       if (name_back[0] != DEFAULT_ERROR_NAME) {

            char *pCameraName =strtok(name_back, ",");

            while (pCameraName != NULL) {

                ALOGI("Checking the camera%s", pCameraName);

                strncpy(sCameraInfo[gCameraNum].name,

                        pCameraName,

                        CAMERA_SENSOR_LENGTH);

                sCameraInfo[gCameraNum].facing      = CAMERA_FACING_BACK;

                sCameraInfo[gCameraNum].orientation= back_orient;

                memset(sCameraInfo[gCameraNum].devPath,0, CAMAERA_FILENAME_LENGTH);

               if(GetDevPath(sCameraInfo[gCameraNum].name,

                           sCameraInfo[gCameraNum].devPath,

                           CAMAERA_FILENAME_LENGTH)== -1){

                    pCameraName = strtok(NULL,",");

                    continue;

                }

                ALOGI("Camera ID %d: name%s, Facing %d, orientation %d, dev path %s",

                        gCameraNum,

                        sCameraInfo[gCameraNum].name,

                        sCameraInfo[gCameraNum].facing,

                        sCameraInfo[gCameraNum].orientation,

                        sCameraInfo[gCameraNum].devPath);

                gCameraNum++;

                break;

            }

       }

       if (name_front[0] != DEFAULT_ERROR_NAME) {

            char *pCameraName =strtok(name_front, ",");

            while (pCameraName != NULL) {

                ALOGI("Checking the camera%s", pCameraName);

                strncpy(sCameraInfo[gCameraNum].name,

                        pCameraName,

                        CAMERA_SENSOR_LENGTH);

                sCameraInfo[gCameraNum].facing      = CAMERA_FACING_FRONT;

                sCameraInfo[gCameraNum].orientation= front_orient;

                memset(sCameraInfo[gCameraNum].devPath,0, CAMAERA_FILENAME_LENGTH);

                if(GetDevPath(sCameraInfo[gCameraNum].name,

                       sCameraInfo[gCameraNum].devPath,

                       CAMAERA_FILENAME_LENGTH)== -1) {

                    pCameraName = strtok(NULL, ",");

                    continue;

                }

                ALOGI("Camera ID %d: name%s, Facing %d, orientation %d, dev path %s",

                    gCameraNum,

                    sCameraInfo[gCameraNum].name,

                    sCameraInfo[gCameraNum].facing,

                    sCameraInfo[gCameraNum].orientation,

                    sCameraInfo[gCameraNum].devPath);

                gCameraNum++;

                break;

            }

       }

   }

   return gCameraNum;

}

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值