Camera Inside App Force Close Data Null When I Try In Different Device
Solution 1:
The crash is happening inside the device's Camera application, not your own. Unfortunately, because the Camera application on this device could be a heavily customized variation of what is actually in AOSP, it's not entirely clear what the failure is, but here is a link to the source file in the AOSP 2.3.7 source tree where your exception is occurring. The line numbers don't match up exactly to anything of interest, which is what tells me the application on your particular device has been customized at least some.
Any object in the initializeFirstTime()
method, where the exception occurs, where a method is called could be the source of the issue, but none of this is related to the Intent
parameters your request passes in, so it is doubtful there is much you can do to make this operate appropriately.
As a result, you may have better luck implementing the capture functionality yourself in your own application. It is likely that the Android APIs on this device are more stable than the system applications it's bundled with. Here is an example of how you can create your own camera preview and capture Activity.
Solution 2:
I'm curious about your phone. what the different of them
because of your onCaptureImage(View v) does describe about external storage. but onCaptureVideo(View v) doesn't
the phone that didn't work. is it support external sd card? if it not, all your code is about ext.sd
Is it your phone that didn't work it remove sd card occasionally? try connect it as camera or mtp
Solution 3:
Friend Do one thing.
Make Simple app which have only one button. onClick
event photo should be capture no add other task.
Is it working Properly ?
Solution 4:
try to catch the exception and post the message here:
try{
IntentcameraIntent=newIntent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
catch(ActivityNotFoundException e){
e.printStackTrace();
}
Solution 5:
Thanks @Devunwired, thanks @chintan and thanks all for helping me. i use camera api and it works.
this is my activity
package com.exercise.AndroidCamera;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import android.app.Activity;
import android.content.ContentValues;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore.Images.Media;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
publicclassAndroidCameraextendsActivityimplementsSurfaceHolder.Callback{
Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
booleanpreviewing=false;
LayoutInflatercontrolInflater=null;
finalintRESULT_SAVEIMAGE=0;
/** Called when the activity is first created. */@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
}
publicvoidonCaptureImage(View v)
{
setContentView(R.layout.main);
Toast.makeText(AndroidCamera.this,
"Image dimulai : ",
Toast.LENGTH_LONG).show();
getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
controlInflater = LayoutInflater.from(getBaseContext());
ViewviewControl= controlInflater.inflate(R.layout.control, null);
LayoutParamslayoutParamsControl=newLayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
this.addContentView(viewControl, layoutParamsControl);
ButtonbuttonTakePicture= (Button)findViewById(R.id.takepicture);
buttonTakePicture.setOnClickListener(newButton.OnClickListener(){
@OverridepublicvoidonClick(View arg0) {
// TODO Auto-generated method stub
camera.takePicture(myShutterCallback,
myPictureCallback_RAW, myPictureCallback_JPG);
}});
}
ShutterCallbackmyShutterCallback=newShutterCallback(){
@OverridepublicvoidonShutter() {
// TODO Auto-generated method stub
}};
PictureCallbackmyPictureCallback_RAW=newPictureCallback(){
@OverridepublicvoidonPictureTaken(byte[] arg0, Camera arg1) {
// TODO Auto-generated method stub
}};
PictureCallbackmyPictureCallback_JPG=newPictureCallback(){
@OverridepublicvoidonPictureTaken(byte[] arg0, Camera arg1) {
// TODO Auto-generated method stub/*Bitmap bitmapPicture
= BitmapFactory.decodeByteArray(arg0, 0, arg0.length); */UriuriTarget= getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, newContentValues());
OutputStream imageFileOS;
try {
imageFileOS = getContentResolver().openOutputStream(uriTarget);
imageFileOS.write(arg0);
imageFileOS.flush();
imageFileOS.close();
Toast.makeText(AndroidCamera.this,
"Image Tersimpan: " + uriTarget.toString(),
Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*controlInflater = LayoutInflater.from(getBaseContext());
View viewControl = controlInflater.inflate(R.layout.confirm, null);
LayoutParams layoutParamsControl
= new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
this.addContentView(viewControl, layoutParamsControl);*/
}};
@OverridepublicvoidsurfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stubif(previewing){
camera.stopPreview();
previewing = false;
}
if (camera != null){
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewing = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@OverridepublicvoidsurfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
//m_camera = Camera.open();/*Camera.Parameters p = camera.getParameters();
//camera.setDisplayOrientation(90);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
{
p.set("orientation", "portrait");
p.set("rotation",90);
}
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
{
p.set("orientation", "landscape");
p.set("rotation", 90);
}*/
}
@OverridepublicvoidsurfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}
}
i create home.xml to show button image like my question
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><Buttonandroid:text="Capture Image"android:onClick="onCaptureImage"android:layout_width="wrap_content"android:layout_height="wrap_content"/></LinearLayout>
main.xml this is a camera preview
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"
><SurfaceViewandroid:id="@+id/camerapreview"android:layout_width="fill_parent"android:layout_height="wrap_content"
/></LinearLayout>
and create control.xml take picture button inside camera preview.
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"android:gravity="bottom"
><Buttonandroid:id="@+id/takepicture"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text=" * Ambil Foto "android:layout_gravity="right"android:layout_margin="10px"
/></LinearLayout>
but i have 2 problem in this app.
- the camera resolution not full size . -+20kb
- when take camera preview is rotate 90 degrees
Post a Comment for "Camera Inside App Force Close Data Null When I Try In Different Device"