本文介绍了使用意图使用相机在安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的code。通过使用意图使用相机。在意向中的参数我传递 android.provider.MediaStore.ACTION_IMAGE_CAPTURE
。它是能够打开相机。但问题是,它意外停止。现在的问题是,它给空指针异常的 OnActivityResults
。我已经使用了低于code:
I am using the following code to use camera by using intent.In the parameter of intent I am passing android.provider.MediaStore.ACTION_IMAGE_CAPTURE
.It is able to open the camera.But the problem is that it stops unexpectedly.The problem is that it gives null pointer exception on OnActivityResults
.I have used the below code:
public class demo extends Activity {
Button ButtonClick;
int CAMERA_PIC_REQUEST = 2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ButtonClick =(Button) findViewById(R.id.Camera);
ButtonClick.setOnClickListener(new OnClickListener (){
@Override
public void onClick(View view)
{
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
// request code
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if( requestCode == CAMERA_PIC_REQUEST)
{
// data.getExtras()
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image =(ImageView) findViewById(R.id.PhotoCaptured);
image.setImageBitmap(thumbnail);
}
else
{
Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG);
}
super.onActivityResult(requestCode, resultCode, data);
}
}
谁能帮我解决这个问题?
Can anyone help me to solve this problem?
推荐答案
尝试请求code 1337。
Try request code 1337.
startActivityForResult(cameraIntent , 1337);
这篇关于使用意图使用相机在安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!