Can't Get Camera Code From Android Docs To Work
Solution 1:
That's one of notorious Android development experience.
Android Intent does not guarantee to give captured image in data.getExtras()
, especially user utilize 3rd party camera/imaging app. You can find many trials and suggestions in here and anywhere googled with "android camera intent null".
Some common of them are as below.
data.getExtras().get("data");
data.getExtras()
with different key (i.e "photo")data.getData()
Uri.fromFile(f)
forEXTRA_OUTPUT
predefined path.Uri.fromFile(f)
with some random filename (datetime format or IMG-xxx) without maintainingEXTRA_OUTPUT
definition.
I recommend you to find it using breakpoint which route of the variable that the intent given. It would be good to check all of them in if-else if-else
approach.
In addition, check out crash report carefully after releasing the app. You may get the error out of the above trials.
Solution 2:
To get the ThumbNail, you don't need to create a file etc. please try this code below.
IntenttakePictureIntent=newIntent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intentif (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
and to get the results.
@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundleextras= data.getExtras();
BitmapimageBitmap= (Bitmap) extras.get("data");
imgView.setImageBitmap(imageBitmap);
}
}
imgView is the ImageView you want to set the ThumbNail to.
In case if you want to create a file and then try this, [ which is not needed for a Thumbnail], you may want to try adding the following permission to manifest as you are trying to read and write to storage.
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE"/>
All the best.
Post a Comment for "Can't Get Camera Code From Android Docs To Work"