简体   繁体   中英

Camera does not open in android app

Hi guys I am trying to take a snapshot from my app which uses the existing camera app in the device. I have followed the steps provided on Android developers site.

public boolean onMenuItemSelected(int featureId, MenuItem item) {
    // TODO Auto-generated method stub
    switch(item.getItemId()){
    case R.id.pic_take:
        i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, cameraData);
        return true;
    }
    return super.onMenuItemSelected(featureId, item);
}

followed by this:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == cameraData && resultCode == RESULT_OK){
        Bundle extras = data.getExtras();
        bmp = (Bitmap) extras.get("data");
        cameraView.setImageBitmap(bmp);

    }
}

I have also made sure that my emulator has the front and back camera enabled.

Please do no close this question. The problem is when I select the option the camera does not open and there is no errors as well in the activity log. Neither does the application crash: When I click the option, the only message I get in activity log is :

04-01 17:44:16.665: I/Choreographer(1227): Skipped 48 frames!  The application may be doing too much work on its main thread.

Kindly help me solve this problem.

想知道您是否在AndroidManifest.xml中声明了相机许可。

<uses-permission android:name="android.permission.CAMERA" />

things like camera sometimes wont work on emulator properly ... if you can, i would suggest you to try it on real device ... also for that error

Skipped 48 frames!  The application may be doing too much work on its main thread.

The message you are seeing is important on phones but not in the emulator. The emulator is extremely slow. Nothing you are doing is resource intensive so your application should perform nominally on a device.

So the result, please try it on real device (and it will work) :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM