2017-02-22 115 views
0

我無法使用getWindow內部服務查看。如何獲取應用程序之外的任何屏幕的視圖?

我將此視圖用於外部應用程序的任何屏幕。

View v1 = getWindow().getDecorView().getRootView(); 

如何在服務中捕獲屏幕截圖?

或者我如何獲得外部應用程序之外的任何屏幕的視圖?

+0

請閱讀這些:[page1](http://stackoverflow.com/help/how-to-ask)[page2](http://stackoverflow.com/help/mcve)[page3](http:/ /stackoverflow.com/help/on-topic) –

回答

0

衝牀線:你在提問時很不好。

但我會盡力回答我明白的問題。

如何截屏?

private void getScreenshot() { 

try { 

    String imagePath = Environment.getExternalStorageDirectory().toString() + "/" + /*NAME*/ + ".jpg"; 

    View view = getWindow().getDecorView().getRootView(); 
    view.setDrawingCacheEnabled(true); 
    Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); 
    view.setDrawingCacheEnabled(false); 

    File imageFile = new File(imagePath); 

    FileOutputStream outputStream = new FileOutputStream(imageFile); 
    int quality = 100; 
    bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream); 
    outputStream.flush(); 
    outputStream.close(); 

} catch (Throwable e) { 
    e.printStackTrace(); 
} 
} 

現在就做你想做的事。

而且我不明白你要問什麼,

View v1 = getWindow().getDecorView().getRootView();

可以進一步,如果你想澄清。

相關問題