diff --git a/interiAR/app/src/main/AndroidManifest.xml b/interiAR/app/src/main/AndroidManifest.xml index 973ecc8..ab8568e 100644 --- a/interiAR/app/src/main/AndroidManifest.xml +++ b/interiAR/app/src/main/AndroidManifest.xml @@ -4,6 +4,7 @@ + = Build.VERSION_CODES.N) { - PixelCopy.request(view, bitmap, (copyResult) -> { - if (copyResult == PixelCopy.SUCCESS) { - Toast.makeText(getApplicationContext(),"Screenshot taken",Toast.LENGTH_SHORT).show(); - handleUpload(bitmap); - } else { - Toast toast = Toast.makeText(getApplicationContext(), "Failed to take screenshot !" + copyResult, Toast.LENGTH_LONG); - toast.show(); + // Make the request to copy. + PixelCopy.request(view, bitmap, (copyResult) -> { + if (copyResult == PixelCopy.SUCCESS) { + Log.e("save","save"); + try { + saveBitmapToDisk(bitmap); + } catch (IOException e) { + e.printStackTrace(); } - handlerThread.quitSafely(); - }, new Handler(handlerThread.getLooper())); + + + + } else { + + Toast.makeText(MainActivity3.this, "screenshot cannot saved", + Toast.LENGTH_LONG).show(); + + } + handlerThread.quitSafely(); + }, new Handler(handlerThread.getLooper())); + } + + + public void saveBitmapToDisk(Bitmap bitmap) throws IOException { + + if (videoDirectory == null) { + videoDirectory = + new File(String.valueOf(new File( + + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + + "/Screenshots"))); } + + Calendar c = Calendar.getInstance(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss"); + String formattedDate = df.format(c.getTime()); + + File mediaFile = new File(videoDirectory, "RoomViz"+formattedDate+".jpeg"); + + FileOutputStream fileOutputStream = new FileOutputStream(mediaFile); + bitmap.compress(Bitmap.CompressFormat.JPEG, 70, fileOutputStream); + fileOutputStream.flush(); + fileOutputStream.close(); } + private void handleUpload(Bitmap bitmap){ String user= FirebaseAuth.getInstance().getCurrentUser().getEmail(); ByteArrayOutputStream baos=new ByteArrayOutputStream();