porting screen shot java app on android
i want your help very badly..bcz i am seeking an answer for this from couple of day's but did not find a bit...
my query is i have a screen shot app written in java...i just want to port it on android emulator and run it..i know i have to rewrite some android specific code but can anyone tell me what changes i should make to the screen shot java app to make it run on android platform.. here is my java screen shot app: (i know for this the device should be rooted i am okay for that)
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
class Screen开发者_运维百科Capture {
public static void main(String args[]) throws
AWTException, IOException {
// capture the whole screen
BufferedImage screencapture = new Robot().createScreenCapture(
new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );
// Save as JPEG
File file = new File("screencapture.jpg");
ImageIO.write(screencapture, "jpg", file);
// Save as PNG
// File file = new File("screencapture.png");
// ImageIO.write(screencapture, "png", file);
}
}
There aren't just a few changes that you have to made. You have to rewrite the whole app and that wouldn't be so easy since making screenshots in Android isn't this easy as in plain Java.
For example you can't use java.awt.Robot because this lib isn't included in Android.
Afaik you also need root rights on a Android phone to make a screenshot. I would recommend that you google for librarys or apps that are already able to do screenshots and use them.
For example the Android Screenshot Library (ASL) is a good point to start with.
精彩评论