woo*_*ody 1 android android-camera android-camera-intent
嘿伙计我刚为用户添加了一项功能,可以从我的应用程序中捕获图片,并且我已正确设置相机意图[我至少相信如此].我在'xml'文件中设置了一个按钮,并在'class/java'文件中相应地设置了intent和按钮.当测试应用程序按钮工作并加载本机Android 4.0.4相机,并拍摄照片很好,但当我点击'选中标记'[旧版Android上的'确定'按钮]它不会返回到应用程序.相机仍然保持所有功能,它不会冻结或任何东西.我仍然可以选择重拍,或选择取消; 只是'确定/选中标记'按钮不起作用.
public class XXXXXXXXXXX extends Activity
{
Button button;
String path;
boolean taken;
static final String PHOTO_TAKEN = "photo_taken";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.XXXXXXXX);
button = ( Button ) findViewById( R.id.take_picture );
button.setOnClickListener( new ButtonClickHandler() );
path = Environment.getExternalStorageDirectory() + "/images/testing-cam.jpg";
}
public class ButtonClickHandler implements View.OnClickListener
{
public void onClick( View view )
{
Log.i("Button", ".onClick()" );
startCameraActivity();
}
}
protected void startCameraActivity()
{
Log.i("Start", "CameraActivity()" );
File file = new File( _path );
Uri outputFileUri = Uri.fromFile( file );
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
startActivityForResult( intent, 0 );
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch( resultCode )
{
case 0:
break;
case -1:
onPhotoTaken();
break;
}
}
protected void onPhotoTaken()
{
taken = true;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap bitmap = BitmapFactory.decodeFile( _path, options );
image.setImageBitmap(bitmap);
field.setVisibility( View.GONE );
}
Run Code Online (Sandbox Code Playgroud)
如果需要任何其他代码我可以提供它,但这是我在我的应用程序中使用的主要相机代码.
你在Mainfest中使用过这个吗?
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
Run Code Online (Sandbox Code Playgroud)
你也可以关注这个链接.
http://www.vogella.com/articles/AndroidCamera/article.html
http://marakana.com/forums/android/examples/39.html