Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:无根屏幕捕获_Android_Image_File_Screen - Fatal编程技术网

Android:无根屏幕捕获

Android:无根屏幕捕获,android,image,file,screen,Android,Image,File,Screen,我尝试了下面的代码,但当我运行它时,它在android mobile上显示了一个黑屏图像,在emulator上显示了一个文件,打开这个文件,我会得到一条消息:预览不可用 请有人帮忙。谢谢。那好吧。您可能必须重写下面的方法。问题是因为您的视图尚未创建,甚至在创建之前,您试图获取实际不存在的背景,因此无法获取任何图像 试试这个 @Override public void onWindowFocusChanged(boolean hasFocus) { // add the entire

我尝试了下面的代码,但当我运行它时,它在android mobile上显示了一个黑屏图像,在emulator上显示了一个文件,打开这个文件,我会得到一条消息:预览不可用


请有人帮忙。谢谢。那好吧。您可能必须重写下面的方法。问题是因为您的视图尚未创建,甚至在创建之前,您试图获取实际不存在的背景,因此无法获取任何图像

试试这个

 @Override 
public void onWindowFocusChanged(boolean hasFocus) 
{ 
   // add the entire code for getting the background within this and it will work 
} 

一旦绘制视图,就会调用此方法,因此您将通过重写此方法获得所需的输出

这在onCreate()中不起作用,因为该活动只有在onCreate()完成后才可见。
在onCreate()完成时触发一些事件以运行代码。可能是按钮事件的onClick()。

您是在Click事件中执行此操作,还是直接在oncreate()中执行此操作?可能您的活动视图尚未在oncreate()中绘制,对于测试,点击一个按钮并编写屏幕截图代码。你能建议我是否使用此方法到另一个活动类并在服务上调用它,然后它工作还是不工作吗?嘿,Andro,现在我遇到了另一个问题,因为它工作了6到10次,现在此代码工作不正常。再次显示“预览不可用”;请帮忙。。谢谢你
 @Override 
public void onWindowFocusChanged(boolean hasFocus) 
{ 
   // add the entire code for getting the background within this and it will work 
}