0

How do I make the application take a screenshot every 30 seconds and then the following code here will run? (The code for the screenshot is also attached here)

ImageView imgGallery;
TextView textView;
Bitmap img;
String ScreenshotText;
imgGallery = findViewById(R.id.imageId);
textView = findViewById(R.id.textId);
                
img = captureScreenShot(MainActivity.this);
                 
FirebaseVisionImage firebaseVisionImage = FirebaseVisionImage.fromBitmap(img);
FirebaseVision firebaseVision = FirebaseVision.getInstance();
FirebaseVisionTextRecognizer firebaseVisionTextRecognizer = firebaseVision.getOnDeviceTextRecognizer();
Task<FirebaseVisionText> task = firebaseVisionTextRecognizer.processImage(firebaseVisionImage);
task.addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
    @Override
    public void onSuccess(FirebaseVisionText firebaseVisionText) {
        ScreenshotText = firebaseVisionText.getText();
    }
});

task.addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception e) {
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }
});
            
public Bitmap captureScreenShot(Activity activity) {
    View view = activity.getWindow().getDecorView().getRootView();
    view.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
    view.setDrawingCacheEnabled(false);
    return bitmap;
}
HoRn
  • 1,458
  • 5
  • 20
  • 25
  • Welcome to Stack Overflow! You are encouraged to make an attempt to write your code. If you encounter a specific technical problem during that attempt, such as an error or unexpected result, we can help with that. Please provide specific information about that attempt and what didn't work as expected. To learn more about this community and how we can help you, please start with the tour and read [ask] and its linked resources – HoRn Sep 03 '22 at 15:06

0 Answers0