2014-02-13 30 views
0

我创建了一个在其他应用上运行的服务。我希望服务能够在用户看到整个屏幕时截取屏幕截图,而不管正在运行什么应用。我可以让该服务运行手机的屏幕截图功能并将其存储在特定位置吗?在Android中从服务中获取屏幕截图

+0

据我所知,这是无法完成的。您只能截取您应用中的内容。 –

回答

3

我可以让服务运行手机的屏幕截图功能并将其存储在特定位置吗?

否,除了可能在根植设备上,出于明显的隐私和安全原因。

0

好,类似的问题一直非常受欢迎的计算器:

How to programmatically take a screenshot in Android?

How to take screenshot programmatically?

how to take screenshot programmatically and save it on gallery?

特别是,这个人是有用的:

// image naming and path to include sd card appending name you choose for file 
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + 
ACCUWX.IMAGE_APPEND; 

// create bitmap screen capture 
Bitmap bitmap; 
View v1 = mCurrentUrlMask.getRootView(); 
v1.setDrawingCacheEnabled(true); 
bitmap = Bitmap.createBitmap(v1.getDrawingCache()); 
v1.setDrawingCacheEnabled(false); 

OutputStream fout = null; 
imageFile = new File(mPath); 

try { 
    fout = new FileOutputStream(imageFile); 
    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout); 
    fout.flush(); 
    fout.close(); 

} catch (FileNotFoundException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

由Mualig,从上面的帖子之一。