【问题标题】:How to save files on different mobile devices with and without sd cards?如何在有和没有 sd 卡的不同移动设备上保存文件?
【发布时间】:2013-05-31 06:37:17
【问题描述】:

我将我的应用程序上传到 google play,之后我发现我的应用程序并没有在我检查过的所有设备上运行,除了我自己的...

我认为问题是文件保存位置的结果,我使用以下代码:

但是在没有 SD 卡的设备中会发生什么?

在 logcat 中我收到错误“创建目录失败”

    // Step 4: Set output file
    mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO)
            .toString());
    outputFileName = getOutputMediaFile(MEDIA_TYPE_VIDEO).toString();





/** 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_MOVIES),
            "Your_voice");
    // 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("Your_voice_App", "failed to create directory");
            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("ddMMyy_HHmmss")
            .format(new Date());
    File mediaFile;
    if (type == MEDIA_TYPE_VIDEO) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "Your_voice" + timeStamp + ".mp4");
    } else {
        return null;
    }

    return mediaFile;
}

【问题讨论】:

    标签: android android-camera android-sdcard android-file


    【解决方案1】:

    然后,您无需启动 PC 即可查看、编辑和快速共享它们。它还可以让您观看存储在卡上的视频,这意味着您无需用巨大的视频文件占用宝贵的内部存储空间。

    http://resultplanet.org/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      • 1970-01-01
      • 1970-01-01
      • 2017-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多