内部存储截图保护程序

时间:2014-11-07 18:36:19

标签: android

我想在Android上的内部存储中保存屏幕截图。我设法将其保存在外部存储上但是如何修改此代码以便将其保存在内部存储中?

            if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
            {
                File sdCard=Environment.getExternalStorageDirectory();
                File directory=new File(sdCard.getAbsolutePath()+"/DCIM"+"/Camera");
                directory.mkdirs();
                String filename="screenshot"+i+".jpg";
                File yourFile=new File(directory,filename);
                while(yourFile.exists())
                {
                    i++;
                    filename="screenshot"+i+".jpg";
                    yourFile = new File(directory, filename);

                }
                if(!yourFile.exists())
                {
                    if(directory.canWrite())
                    {
                                   try {
                                       FileOutputStream out = new FileOutputStream(yourFile,true);
                                   bitmap.compress(Bitmap.CompressFormat.JPEG,90,out);
                                   out.flush();
                                   out.close();
                                       Toast.makeText(getBaseContext(), "File exported to /sdcard/Tutorial_ScreenShot/screenshot" + i + ".jpg", Toast.LENGTH_SHORT).show();
                                       i++;
                                   }
                                   catch (IOException e)
                                   {
                                       e.printStackTrace();
                                   }
                    }
                }
            }
            else
            {
                Toast.makeText(getBaseContext(), "SD Card not available!", Toast.LENGTH_SHORT).show();
            }
        }
    });

0 个答案:

没有答案