Sdk写文件:
/*****************************************************************************************************
* Function: buildFile
* Description: buildFile
* Input:
* Output:
* Return:
****************************************************************************************************/
private void creadPicFolder()
{
String sDStateString = android.os.Environment.getExternalStorageState();
if (sDStateString.equals(android.os.Environment.MEDIA_MOUNTED))
{
try
{
// 获取扩展存储设备的文件目录
File SDFile = android.os.Environment.getExternalStorageDirectory();
//创建文件夹
File mfilePicFolder = new File(SDFile.getAbsolutePath()+File.separator+"mfile");
//判断是否存在,不存在就创建
if (!mfilePicFolder.exists())
{
mfilePicFolder.mkdir();
mfilePicFolder.createNewFile();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
/*******************************************************************
* Function: buildCaptionPic()
* Description: 从XML 提前UI
* Input: none
* Output: none Return: none
*******************************************************************/
private void buildCaptionPic()
{
try
{
Calendar calendar = Calendar.getInstance();
String fileName = String.format("%04d%02d%02d%02d%02d%02d",
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH),
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
calendar.get(Calendar.SECOND));
Log.d("TCP","fileName is: "+ fileName);
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
{
//判断目录和文件是否存在
File path = new File("/sdcard/mfile");
captionPic = new File("/sdcard/mfile/"+fileName+".png");
if (!path.exists())
{
path.mkdir();
}
if (!captionPic.exists())
{
captionPic.createNewFile();
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
//建立截图文件
buildCaptionPic();
FileOutputStream stream = new FileOutputStream(captionPic);
playView.saveFrame(stream, true);
//保存截图
if (saveOneFrame && null != frameStream)
{
try
{
bmp.compress(Bitmap.CompressFormat.PNG, 60, frameStream);
frameStream.flush();
frameStream.close();
saveOneFrame = false;
Log.d("TCP","dstbmp.compress");
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}