I don't have SD card in my mobile also was hoping people who use my app may or may not have it. Now when I tried to share my screenshot it works in few mobiles and does not work in few. In all these mobiles none of them have SD card. Also I want to make sure that the screenshots should not get saved anywhere so that it will not be visible in the gallery. I tried with the following methods:
- getExternalStorageState()
- getDatadirectory()
- getFilesDir()
- getDir()
- getCacheDir()
But I still couldn't get the right approach in doing so. This is the present code that I'm working on :
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();
}
Now my focus is on sharing the screenshot in a mobile where it does not have SD card and it should not save anywhere so that the screenshots wouldn't keep dumping as I go on sharing. How to do it ?
EDIT : Now I started working on getDir() method so that the files will be getting saved on Application data as noted by my friend Ashish Vora. I have found that the files are getting saved inside but it is not retrieved back for sharing. All I'm getting is a blank screen.