Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将媒体存储目录导出到操作视图中?_Java_Android_Android Intent - Fatal编程技术网

Java 如何将媒体存储目录导出到操作视图中?

Java 如何将媒体存储目录导出到操作视图中?,java,android,android-intent,Java,Android,Android Intent,我在按钮上附加了一个函数,如下所示: public void viewSnappies(View z) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Util.getOutputMediaFile().mediaStorageDir().getPath())); startActivity(intent); } 在我的Util类中,我有: public final class Uti

我在按钮上附加了一个函数,如下所示:

public void viewSnappies(View z) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Util.getOutputMediaFile().mediaStorageDir().getPath()));
        startActivity(intent);
    }
在我的Util类中,我有:

public final class Util {
    /**
     * Create a File for saving an image
     */
    // http://developer.android.com/guide/topics/media/camera.html#saving-media
    public static File getOutputMediaFile(Context context) {
        File mediaStorageDir = null;
        // To be safe, you should check that the SDCard is mounted
        // using Environment.getExternalStorageState() before doing this.
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "snappiesticker");
        } else {
            ContextWrapper cw = new ContextWrapper(context);
            mediaStorageDir = cw.getDir("imageDir", Context.MODE_PRIVATE);
        }


        // 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()) return null;
        }

        // Create a media file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        File mediaFile;

        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");

        return mediaFile;
    }
}
现在,按钮不工作,因为我希望它在新的意图行中出错。它无法解析,因为我在Uri.parse中放入了错误的内容。我希望它解析并使用Util类中给定的getOutputMediaFile方法中定义的mediaStorageDir


如何正确传递此变量

然后返回mediaStorageDir而不是mediaFile。因此,更改函数的返回类型。但我需要两者。应用程序的另一部分使用mediaFile。我将如何设置两者的返回格式?然后可以分别给他们打电话?。另外,我将使用什么来代替文件作为输出类型?然后添加另一个返回mediaStorageDir的函数。类型也是File。不,当您使用util.getOutputMediaFile.getParentFile.getAbsolutePath获取mediaStorage目录时,不需要该类型。我将向getOutputMediaFile传递哪些参数?现在它告诉我:Util中的getOutputMediaFileContext不能应用于