Maybe this will help?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
On Wednesday, August 29, 2012 3:03:15 PM UTC-5, aek wrote:
--
Thank you,
Yes indeed it was a pb of permission. Now I saw some light. However still I have a pb that concerns the saving
(The picture can not be saved).
In the procedure done () { ....},
the variable url = null and I dont know why Images.Media.insertImage(getContentResolver(), bm, null, null); is returning
a null value, although I pressed on the button and the camera seems, it worked normally (it made the normal sound of taking
a picture).
thank you very much guys
On Wednesday, August 29, 2012 8:48:18 AM UTC+1, cpares wrote:Hello!Have you requested for permission to use the camera in the manifest? Something like this:<uses-permission android:name="android.permission.CAMERA" /> (and maybe <uses-permission android:name="android.permission.AUTOFOCUS" /> too?) Good luck!
On Wednesday, August 29, 2012 3:53:52 AM UTC+2, aek wrote:
Hi guys,
I am trying to learn android hardware programming. an example of camera programming, I took from a book, which is as listed bellow.
However unfortunately I am geting an error. "a process stops unexpectdly". the pb I guess as per to what is shown by the log cat, is due to
a pb of connecting to the camera service. guys I need your help,
thank you!
--------------------------------- program
package com.example.chapter7_hardware;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.provider.MediaStore.Images;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
import android.support.v4.app.NavUtils;
public class CameraApplication extends Activity implements SurfaceHolder.Callback{
private static final String TAG = "cookbook.hardware";
private LayoutInflater mInflater = null;
Camera mCamera;
byte[] tempdata;
boolean mPreviewRunning = false;
private SurfaceHolder mSurfaceHolder;
private SurfaceView mSurfaceView;
Button takepicture;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//
getWindow().setFormat(PixelFormat.TRANSLUCENT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN, WindowManager.LayoutParams. FLAG_FULLSCREEN);
setContentView(R.layout.activity_camera_application);
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_ PUSH_BUFFERS);
mInflater = LayoutInflater.from(this);
View overView = mInflater.inflate(R.layout.cameraoverlay, null);
this.addContentView(overView, new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
takepicture = (Button) findViewById(R.id.button1);
takepicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mCamera.takePicture(mShutterCallback, mPictureCallback, mjpeg);
}
});
}
ShutterCallback mShutterCallback = new ShutterCallback(){
@Override
public void onShutter(){}
};
PictureCallback mPictureCallback = new PictureCallback(){
@Override
public void onPictureTaken(byte[] data, Camera c){}
};
PictureCallback mjpeg = new PictureCallback(){
public void onPictureTaken(byte[] data, Camera c){
if (data != null){
tempdata = data;
done();
}
}
};
void done() {
Bitmap bm = BitmapFactory.decodeByteArray(tempdata, 0, tempdata.length);
String url = Images.Media.insertImage(getContentResolver(), bm, null, null);
bm.recycle();
Bundle bundle = new Bundle();
if (url != null){
bundle.putString("url", url);
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
} else {
Toast.makeText(this, "Picture can not be saved", Toast.LENGTH_LONG).show();
}
finish();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_camera_ application, menu);
return true;
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// TODO Auto-generated method stub
Log.e(TAG, "surfaceChanged");
try{
if (mPreviewRunning){
mCamera.stopPreview();
mPreviewRunning = false;
}
Camera.Parameters p = mCamera.getParameters();
p.setPreviewSize(w, h);
mCamera.setParameters(p);
mCamera.setPreviewDisplay(holder);
mCamera.startPreview();
mPreviewRunning = true;
} catch (Exception e) {
Log.d("", e.toString());
}
}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
Log.e(TAG, "surfaceCreated");
mCamera = Camera.open();
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub
Log.e(TAG, "surfaceDestroyed");
mCamera.stopPreview();
mPreviewRunning = false;
mCamera.release();
mCamera = null;
}
}
-------------------------------- log cat
08-29 01:48:43.313: E/prog.hardware(395): surfaceCreated
08-29 01:48:43.345: D/AndroidRuntime(395): Shutting down VM
08-29 01:48:43.345: W/dalvikvm(395): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-29 01:48:43.383: E/AndroidRuntime(395): FATAL EXCEPTION: main
08-29 01:48:43.383: E/AndroidRuntime(395): java.lang.RuntimeException: Fail to connect to camera service
08-29 01:48:43.383: E/AndroidRuntime(395): at android.hardware.Camera.native_setup(Native Method)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.hardware.Camera.<init>(Camera.java:110)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.hardware.Camera.open(Camera.java:90)
08-29 01:48:43.383: E/AndroidRuntime(395): at com.example.chapter7_hardware.CameraApplication. surfaceCreated( CameraApplication.java:167)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.SurfaceView.updateWindow(SurfaceView.java: 532)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.SurfaceView.dispatchDraw(SurfaceView.java: 339)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.ViewGroup.dispatchDraw(ViewGroup.java: 1367)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.ViewGroup.dispatchDraw(ViewGroup.java: 1367)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.View.draw(View.java:6743)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.widget.FrameLayout.draw(FrameLayout.java:352)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.ViewGroup.dispatchDraw(ViewGroup.java: 1367)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.View.draw(View.java:6743)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.widget.FrameLayout.draw(FrameLayout.java:352)
08-29 01:48:43.383: E/AndroidRuntime(395): at com.android.internal.policy.impl.PhoneWindow$DecorView. draw(PhoneWindow.java:1842)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.ViewRoot.draw(ViewRoot.java:1407)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.ViewRoot.performTraversals(ViewRoot. java:1163)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.view.ViewRoot.handleMessage(ViewRoot.java: 1727)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.os.Handler.dispatchMessage(Handler.java: 99)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.os.Looper.loop(Looper.java:123)
08-29 01:48:43.383: E/AndroidRuntime(395): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-29 01:48:43.383: E/AndroidRuntime(395): at java.lang.reflect.Method.invokeNative(Native Method)
08-29 01:48:43.383: E/AndroidRuntime(395): at java.lang.reflect.Method.invoke(Method.java:521)
08-29 01:48:43.383: E/AndroidRuntime(395): at com.android.internal.os.ZygoteInit$ MethodAndArgsCaller.run( ZygoteInit.java:868)
08-29 01:48:43.383: E/AndroidRuntime(395): at com.android.internal.os.ZygoteInit.main(ZygoteInit. java:626)
08-29 01:48:43.383: E/AndroidRuntime(395): at dalvik.system.NativeStart.main(Native Method)
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
No comments:
Post a Comment