http://lee70.blogspot.kr/2014/01/blog-post.html
안드로이드 스크린샷(화면 캡쳐하기 (코드에서))
package com.example.activity_shot;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Activity av=MainActivity.this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
try {
screenshot(av);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public void screenshot(Activity av2)throws Exception {
View view = av2.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
Bitmap screenshot = view.getDrawingCache();
//Activity.getWindow().getDecorView()
String filename = "screenshot.png";
try {
File f = new File(Environment.getExternalStorageDirectory(), filename);
f.createNewFile();
OutputStream outStream = new FileOutputStream(f);
screenshot.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.close();
} catch (IOException e) {
e.printStackTrace();
}
view.setDrawingCacheEnabled(false);
}
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Activity av=MainActivity.this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
try {
screenshot(av);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public void screenshot(Activity av2)throws Exception {
View view = av2.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
Bitmap screenshot = view.getDrawingCache();
//Activity.getWindow().getDecorView()
String filename = "screenshot.png";
try {
File f = new File(Environment.getExternalStorageDirectory(), filename);
f.createNewFile();
OutputStream outStream = new FileOutputStream(f);
screenshot.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.close();
} catch (IOException e) {
e.printStackTrace();
}
view.setDrawingCacheEnabled(false);
}
}
http://stackoverflow.com/questions/4396059/how-to-simulate-a-touch-event-in-android
view.setOnTouchListener(new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
Toast toast = Toast.makeText(
getApplicationContext(),
"View touched",
Toast.LENGTH_LONG
);
toast.show();
return true;
}
});
// Obtain MotionEvent object
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
float x = 0.0f;
float y = 0.0f;
// List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(
downTime,
eventTime,
MotionEvent.ACTION_UP,
x,
y,
metaState
);
// Dispatch touch event to view
view.dispatchTouchEvent(motionEvent);
'도산공원' 카테고리의 다른 글
ssh 터널링 -D (0) | 2024.08.08 |
---|---|
ssh 터널링 L (0) | 2024.07.08 |
ssh 터널링 R (0) | 2024.07.08 |