屏幕截图android studio

时间:2016-02-24 08:43:09

标签: java android screenshot

我正在开发一个Android应用程序。常规截图工作正常,但当我尝试允许用户截图整个活动,包括未显示的文本(必须向上或向下滚动)。我已经尝试过这个网站的一些代码,但没有它们有效。我的代码包括截图部分:

 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);
    }
}}

0 个答案:

没有答案