使用相机拍摄照片,将其保存在本地 - 而不是SD卡

时间:2011-08-24 21:35:49

标签: android camera local-storage xoom

正如标题所述,我正在尝试启动相机并拍摄我可以在本地使用APP的照片。这适用于摩托罗拉Xoom,默认情况下,它们不附带SD卡。或者至少我的客户正在考虑购买的没有SD卡。

我找到了一个关于如何启动相机的非常好的教程,我可以让它启动,所有内容都可以实际保存图像,然后能够重新使用该图像。

我发现的很多解决方案或其他教程只显示如何保存到SD卡 - 而不是驻留在内存或本地应用程序。看起来有可能这样做,但我很难过。 : - /

3 个答案:

答案 0 :(得分:2)

您可以将其加载到ContentProvider,以便以后可以使用这些图像:

// Add some parameters to the image that will be stored in the Image ContentProvider
int UNIQUE_BUCKET_ID = 1337;
ContentValues values = new ContentValues(7);
values.put(MediaStore.Images.Media.DISPLAY_NAME,"name of the picture");
values.put(MediaStore.Images.Media.TITLE,"Thats the title of the image");
values.put(MediaStore.Images.Media.DESCRIPTION, "Some description");
values.put(MediaStore.Images.Media.BUCKET_DISPLAY_NAME,"Album name"); 
values.put(MediaStore.Images.Media.BUCKET_ID,UNIQUE_BUCKET_ID);
values.put(MediaStore.Images.Media.DATE_TAKEN,System.currentTimeMillis());
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");

// Inserting the image meta data inside the content provider
Uri uri = getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);

// Filling the real data returned by the picture callback function into the content provider
try {
    OutputStream outStream = getContentResolver().openOutputStream(uri);
    outStream.write(buffer);  // buffer is the data stream returned by the picture callback
    outStream.close();
}catch (Exception e) {
    Log.e(TAG, "Exception while writing image", e);
}

答案 1 :(得分:0)

查看Activity.getFilesDir()Activity.getCacheDir(),它们可以访问存储应用的存储空间。另请查看Environment.getExternalStoragePublicDirectory (),external,here,这意味着在应用程序的私有目录之外。还有其他几个,所以看看API的类似命名方法,找到最适合你。

答案 2 :(得分:0)

因此,您应该注意的一点是,当您致电Environment.getExternalStorageDirectory()时,这不一定对应于外部存储空间(即SD卡),并且会在没有SD卡插槽的设备上返回本地存储空间。

  

注意:不要在这里混淆“外部”这个词。此目录最好被视为媒体/共享存储。它是一个文件系统,可以容纳相对大量的数据,并在所有应用程序之间共享(不强制执行权限)。传统上这是一张SD卡,但它也可以作为内置存储器实现,该设备不同于受保护的内部存储器,可以作为文件系统安装在计算机上。

http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()

同样适用于Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);