我正在为我的应用程序添加一个相机,我基本上决定去添加一个意图,并使用内置的相机。意图的作品,它称它很好,但当它去保存它变得怪异。根据日食照片保存到SD卡,我可以看到他们,并把它们关闭时,我去FileExplorer下。但是,当我真的去探索SD卡时,这些文件不在那里。安卓相机保存,但没有显示在SD卡上
public class C4Main extends Activity {
private static final int REQUEST_CODE = 1;
private Bitmap bitmap;
private ImageView imageView;
private Camera cam;
private SurfaceHolder sh;
private Uri fileUri;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d("testing","before intent");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(1); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
Log.d("testing","fileUri: "+fileUri);
// start the image capture Intent
startActivityForResult(intent, 100);
Log.d("testing","after startactivity");
}
private static Uri getOutputMediaFileUri(int type){
return Uri.fromFile(getOutputMediaFile(type));
}
/** Create a File for saving an image or video */
private static File getOutputMediaFile(int type){
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "MyCameraApp");
// This location works best if you want the created images to be shared
// between applications and persist after your app has been uninstalled.
// Create the storage directory if it does not exist
if (! mediaStorageDir.exists()){
if (! mediaStorageDir.mkdirs()){
Log.d("MyCameraApp", "failed to create directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
if (type == 1){
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"IMG_"+ timeStamp + ".jpg");
Log.d("testing loop","Filepath: "+mediaFile.getPath());
} else if(type == 2) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"VID_"+ timeStamp + ".mp4");
} else {
return null;
}
return mediaFile;
}
}
这是我使用的代码,从developer.google复制。正如我根据Eclipse中的FileExplorer所说,它将保存到指定的路径,但它不在我的SD卡上。我的硬件是运行Android 4.0.3的华硕Transformer prime。 Tha清单设置允许外部书写和相机使用。
任何帮助将不胜感激。
好了,问题还是没有解决,但之后我重新启动平板电脑,照片没在正确的文件显示出来。但是,如果我每次拍照时必须重新启动,它会变得非常烦人。 – 2012-03-17 05:38:11
你的android设备中使用了哪个文件浏览器? – user370305 2012-03-17 05:52:53
它必须是硬件故障。如果我在设备上使用文件管理器,照片就会显示出来,就像它们应该马上显示。但是,如果使用内置的画廊,他们不会出现;如果我在我的实际计算机上使用文件资源管理器也会发生这种情况 感谢user370305-在设备中提及,这让我想到在我的实际设备上使用文件管理器,而不是在计算机上。 – 2012-03-17 06:02:12