我正在爲我的應用程序添加一個相機,我基本上決定去添加一個意圖,並使用內置的相機。意圖的作品,它稱它很好,但當它去保存它變得怪異。根據日食照片保存到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