相机意图根本不起作用
public class CameraintentActivity extends Activity {
String _path, sliderpather;
Button button;
Intent intent;
Uri outputFileUri;
File file;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button)findViewById(R.id.button1);
_path = Environment.getExternalStorageDirectory().getName() + File.separatorChar + "make_machine_example.jpg";
file = new File( _path );
outputFileUri = Uri.fromFile( file );
intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
button.setOnClickListener(
new OnClickListener()
{
public void onClick(View v)
{
startActivityForResult( intent, 0 );
}
}
);
}
}
我希望我的应用程序能够拉起相机,拍照,并将图片保存到我想要的目录中,但它不起作用......
是的,AndroidManifest.xml 包含以下权限
CAMERA WRITE_INTERNAL_STORAGE WRITE_EXTERNAL_STORAGE
public class CameraintentActivity extends Activity {
String _path, sliderpather;
Button button;
Intent intent;
Uri outputFileUri;
File file;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button)findViewById(R.id.button1);
_path = Environment.getExternalStorageDirectory().getName() + File.separatorChar + "make_machine_example.jpg";
file = new File( _path );
outputFileUri = Uri.fromFile( file );
intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
button.setOnClickListener(
new OnClickListener()
{
public void onClick(View v)
{
startActivityForResult( intent, 0 );
}
}
);
}
}
I want my app so it pulls the camera, takes a picture, and saves the picture into my desired directory but it is not working...
and yes the AndroidManifest.xml contains the following permissions
CAMERA WRITE_INTERNAL_STORAGE WRITE_EXTERNAL_STORAGE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有为参数
MediaStore.EXTRA_OUTPUT
发送 file:/// URI。您需要一个内容解析器 URI。来自 javadoc:“Intent-extra 的名称用于指示用于存储所请求的图像或视频的内容解析器 Uri。”
阅读
ContentResolver
了解如何使用该机制来存储信息。You don't sent a file:/// URI for parameter
MediaStore.EXTRA_OUTPUT
. You need a content resolver URI. From the javadoc:"The name of the Intent-extra used to indicate a content resolver Uri to be used to store the requested image or video."
Read up on
ContentResolver
s to see how to use that mechanism to store info.使用下面的代码将正确的 uri 传递给相机活动
目前您的做法是错误的。正如 @Sean Owen 建议你的那样,你发送了错误的 uri。
Use below code to pass the correct uri to the camera activity
Currently you are doing it wrong way. As @Sean Owen had suggest you, you are sending the wrong uri.