In my application, I have a view with customer details, I want to save that view as image or PDF to SD card then print the view through third party application (Otherwise pr
Above code work properly but, image override because of same name so, for avoid this problem add below line:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");
Date now = new Date();
String fileName = formatter.format(now);
f = new File(file.getAbsolutePath()+file.separator+ "image_"+fileName+".png");
Add permission in the manifest file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Use the code below
LinearLayout content = findViewById(R.id.rlid);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
File file,f;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
{
file =new File(android.os.Environment.getExternalStorageDirectory(),"TTImages_cache");
if(!file.exists())
{
file.mkdirs();
}
f = new File(file.getAbsolutePath()+file.seperator+ "filename"+".png");
}
FileOutputStream ostream = new FileOutputStream(f);
bitmap.compress(CompressFormat.PNG, 10, ostream);
ostream.close();
}
catch (Exception e){
e.printStackTrace();
}