我的手机中没有SD卡也希望使用我的应用的人可能有也可能没有。现在,当我尝试分享我的屏幕截图时,它可以在很少的手机中使用,并且在少数手机中不起作用在所有这些手机中,他们都没有SD卡。此外,我想确保屏幕截图不应保存在任何地方,以便它不会在图库中显示。我尝试了以下方法:
但我仍然无法做到这一点。这是我正在处理的当前代码:
view.setDrawingCacheEnabled(true);
view.measure(View.MeasureSpec.makeMeasureSpec(view.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(view.getHeight(), View.MeasureSpec.EXACTLY));
view.layout( view.getLeft(), view.getTop(), view.getLeft() + view.getMeasuredWidth(), view.getTop() + view.getMeasuredHeight());
bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
view.destroyDrawingCache();
view.invalidate();
view.refreshDrawableState();
File path = new File(getApplicationContext().getDir("Default", Context.MODE_ENABLE_WRITE_AHEAD_LOGGING),"myapp");
File directory = new File(path.getAbsolutePath());
directory.mkdirs();
String filename = "myapp" + new Date() + ".png";
File yourFile = new File(directory, filename);
try
{
FileOutputStream out = new FileOutputStream(yourFile, true);
bitmap.compress(Bitmap.CompressFormat.PNG, 90,out);
out.flush();
out.close();
send(yourFile);
}catch (IOException e)
{
e.printStackTrace();
}
现在我的重点是在没有SD卡的移动设备中共享屏幕截图,它不应该保存在任何地方,以便在我继续共享时屏幕截图不会继续倾倒。怎么做?
编辑: 现在我开始研究getDir()方法,以便将文件保存在应用程序数据上,如我的朋友Ashish Vora所述。我发现文件已经保存在里面,但是没有检索回来进行共享。我得到的只是一个空白屏幕。
答案 0 :(得分:1)
最好的方法是使用getDir()保存它。 因此它将在您的应用程序数据中,而在Gallery中不可见。您也可以使用您的应用程序共享它。
所以保存为:
File path = new File( getDir(YOUR_DEFAULT_DIRECTORY_NAME, Context.MODE_ENABLE_WRITE_AHEAD_LOGGING));
File directory = new File(path.getAbsolutePath()+ "/my app");
否则你可以使用:
File directory = new File(getDir("my app", Context.MODE_ENABLE_WRITE_AHEAD_LOGGING));