0

I am developing an android app.The regular screenshot works fine but when I try to allow users to screenshot the whole activity including the text that is not being shown (have to scroll up or down). I have tried some codes from this site but non of them has worked. My code including the screenshot part:

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detailed__info);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    Intent intent = getIntent();

     id = intent.getStringExtra(Urls.MARKER_ID);
    year = intent.getStringExtra(Urls.MARKER_Year);
    info = intent.getStringExtra(Urls.MARKER_Info);

   // editTextId = (TextView) findViewById(R.id.);
    editTextName = (TextView) findViewById(R.id.markerYear);
    editTextDesg = (TextView) findViewById(R.id.detailedInfo);


    //editTextId.setText(id);
    editTextName.setText(year);
    editTextDesg.setText(info);

   // getEmployee();

    //Saving into picture

    findViewById(R.id.download).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Bitmap bitmap = takeScreenshot();
            saveBitmap(bitmap);
        }
    });
}



public void goToMainMap(View view) {
    Intent startNewActivity = new Intent(this, KSA_Map.class);
    startActivity(startNewActivity);
}

public void goToSetting(View view) {
    Intent startNewActivity = new Intent(this, Settings.class);
    startActivity(startNewActivity);
}
//Saving into picture complete

public Bitmap takeScreenshot() {
    View rootView = findViewById(android.R.id.content).getRootView();
    Toast.makeText(Detailed_Info.this, "Success screenshot", Toast.LENGTH_LONG).show();
    rootView.setDrawingCacheEnabled(true);
    return rootView.getDrawingCache();



}
public void saveBitmap(Bitmap bitmap) {
    File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(imagePath);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }
}}
bhk33
  • 11
  • 2

0 Answers0