我有一个附加到按钮的功能,如下所示:
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;
}
}
现在按钮不能正常工作(新Intent行中的错误)。它没有解决,因为我把错误的东西放入Uri.parse()。我希望它解析并使用在Util类中给出的getOutputMediaFile方法中定义的mediaStorageDir。
如何正确传递此变量?