如何让android中的应用程序每隔五分钟捕获一次屏幕?
答案 0 :(得分:2)
尝试以下代码屏幕截图: -
// 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();
}
每5分钟捕获
private final static int INTERVAL = 1000 * 60 * 5; //5 minutes
Handler m_handler;
Runnable m_handlerTask = new Runnable()
{
@Override
public void run() {
doSomething();// call your screen shot method
m_handler.postDelayed(m_handlerTask, INTERVAL);
}
}
void startRepeatingTask()
{
m_handlerTask.run();
}
void stopRepeatingTask()
{
m_handler.removeCallback(m_handlerTask);
}
用于截屏link
每5分钟代码link
答案 1 :(得分:0)
使用此代码:
boolean workDone = false;
final static int ROUNDTRIP_TIMOUT = 5*60*1000;
private boolean timeout() {
int waited = 0;
while (waited < ROUNDTRIP_TIMOUT) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
waited += 100;
if (waited == ROUNDTRIP_TIMOUT) {
captureScreen();
workDone = true;
}
}
return workDone;
}
public void captureScreen()
{
// create bitmap screen capture
Bitmap bitmap;
View v1 = mCurrentUrlMask.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
}
if(timeout())
Log.v(TAG , "Screen Capture");
else
Log.v(TAG , "Not Done");