Android 我的照相机功能坏了
这是我的相机代码。我正在编写一个函数,它使用startActivityForResult来处理结果。但是当我选择ACTION_IMAGE_CAPTURE时,它通常会捕获图片,我可以找到这张图片的使用路径。但是,我在手机里找不到路径。似乎这个代码不能在我的手机上使用,因此我不能在我的手机上保存图片 我的手机型号是索尼xperia C和索尼xperia L 这是我的选择代码Android 我的照相机功能坏了,android,camera,onactivityresult,Android,Camera,Onactivityresult,这是我的相机代码。我正在编写一个函数,它使用startActivityForResult来处理结果。但是当我选择ACTION_IMAGE_CAPTURE时,它通常会捕获图片,我可以找到这张图片的使用路径。但是,我在手机里找不到路径。似乎这个代码不能在我的手机上使用,因此我不能在我的手机上保存图片 我的手机型号是索尼xperia C和索尼xperia L 这是我的选择代码 public void function() { AlertDialog.Builder builder = new
public void function()
{
AlertDialog.Builder builder = new AlertDialog.Builder(repair.this);
builder.setTitle("Please select").setPositiveButton("camera", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int i)
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);
}
}).setNegativeButton("album", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int i)
{
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 2);
}
}).show();
}
这是我的onActivityResult代码
非常感谢你的帮助 这是我给你看的代码
public void initView() {
AlertDialog.Builder builder = new AlertDialog.Builder(repair.this).setMessage("Select")
.setPositiveButton("Camera", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int i) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photoUri = getOutputMediaFileUri(3);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(intent, 1);
}
}).setNegativeButton("Album", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int i) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 2);
}
});
AlertDialog dialog = builder.show();
TextView messageText = (TextView)dialog.findViewById(android.R.id.message);
messageText.setGravity(Gravity.CENTER);
dialog.show();
}
public Uri getOutputMediaFileUri(int type){
return Uri.fromFile(getOutputMediaFile(type));
}
private static File getOutputMediaFile(int type) {
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"Camera"); // Storage Folder
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d("Camera", "Oops! Failed create "+ "Camera" + " directory"); // Error warning
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
File mediaFile;
if (type == 3) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); //Storage Name
} else {
return null;
}
return mediaFile;
}
希望能对您有所帮助。您找到解决此问题的方法了吗??我在我的索尼Xperia CI上也遇到了同样的问题,我必须完成它。谢谢。你能在这里发布你的解决方案吗?回答你自己的问题,然后接受它。。这将对面临同样问题的人们非常有帮助这是索尼的错误。如果使用不带getContentResolver.insertMediaStore.Images.Media.EXTERNAL_CONTENT_URI的内置摄像头,则值;它不会使用内置摄像头存储图片。如果你写了一个会存储两个。所以我不得不写,然后有另一张照片另一个位置,所以可以正常使用。我给你看我的代码,然后下面。你在哪里使用这行代码在上面?getContentResolver.insertMediaStore.Images.Media.EXTERNAL_CONTENT_URI,值;我使用getOutputMediaFileUri3;替换getContentResolver.insertMediaStore.Images.Media.EXTERNAL_CONTENT_URI的值;
public void initView() {
AlertDialog.Builder builder = new AlertDialog.Builder(repair.this).setMessage("Select")
.setPositiveButton("Camera", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int i) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photoUri = getOutputMediaFileUri(3);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(intent, 1);
}
}).setNegativeButton("Album", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int i) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 2);
}
});
AlertDialog dialog = builder.show();
TextView messageText = (TextView)dialog.findViewById(android.R.id.message);
messageText.setGravity(Gravity.CENTER);
dialog.show();
}
public Uri getOutputMediaFileUri(int type){
return Uri.fromFile(getOutputMediaFile(type));
}
private static File getOutputMediaFile(int type) {
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"Camera"); // Storage Folder
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d("Camera", "Oops! Failed create "+ "Camera" + " directory"); // Error warning
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
File mediaFile;
if (type == 3) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); //Storage Name
} else {
return null;
}
return mediaFile;
}