1

I need to take some screen shots, is it possible to use the method 'takeScreenShot' already available in Robotium to take screen shots? I've imported the jar files, but I haven't been too successful. If it is not possible to use robotium can you suggest any other solutions.

public class MyService extends Service {
    Solo solo;
    Context con;
    private Instrumentation it;
    @Override
public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();

        it = new Instrumentation();
        Log.i("My Service", "Instrumentation Obj was created");

    }
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
    // TODO Auto-generated method stub

        solo = new Solo(it);
        if(solo == null)
        Log.i("My Service", "Solo Obj was created");
        solo.takeScreenshot();
        return super.onStartCommand(intent, flags, startId);
    }

Log cat O/P: 03-06 17:27:54.939: W/dalvikvm(1405): VFY: unable to resolve new-instance 468 (Lcom/jayway/android/robotium/solo/Solo;) in Lcom/example/unboundserviceex/MyService; 03-06 17:27:54.949: D/dalvikvm(1405): VFY: replacing opcode 0x22 at 0x0000 03-06 17:27:54.949: D/dalvikvm(1405): DexOpt: unable to opt direct call 0x0cf0 at 0x04 in Lcom/example/unboundserviceex/MyService;.onStartCommand 03-06 17:27:54.949: I/My Service(1405): Instrumentation Obj was created 03-06 17:27:54.959: D/AndroidRuntime(1405): Shutting down VM 03-06 17:27:54.959: W/dalvikvm(1405): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 03-06 17:27:54.979: E/AndroidRuntime(1405): FATAL EXCEPTION: main

03-06 17:27:54.979: E/AndroidRuntime(1405): java.lang.NoClassDefFoundError:

com.jayway.android.robotium.solo.Solo 03-06 17:27:54.979: E/AndroidRuntime(1405): at com.example.unboundserviceex.MyService.onStartCommand(MyService.java:33) 03-06 17:27:54.979: E/AndroidRuntime(1405): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2359) 03-06 17:27:54.979: E/AndroidRuntime(1405): at android.app.ActivityThread.access$1900(ActivityThread.java:123) 03-06 17:27:54.979: E/AndroidRuntime(1405): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210) 03-06 17:27:54.979: E/AndroidRuntime(1405): at android.os.Handler.dispatchMessage(Handler.java:99) 03-06 17:27:54.979: E/AndroidRuntime(1405): at android.os.Looper.loop(Looper.java:137) 03-06 17:27:54.979: E/AndroidRuntime(1405): at android.app.ActivityThread.main(ActivityThread.java:4424) 03-06 17:27:54.979: E/AndroidRuntime(1405): at java.lang.reflect.Method.invokeNative(Native Method) 03-06 17:27:54.979: E/AndroidRuntime(1405): at java.lang.reflect.Method.invoke(Method.java:511) 03-06 17:27:54.979: E/AndroidRuntime(1405): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 03-06 17:27:54.979: E/AndroidRuntime(1405): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 03-06 17:27:54.979: E/AndroidRuntime(1405): at dalvik.system.NativeStart.main(Native Method)

The main error I believe is: java.lang.NoClassDefFoundError

4

2 回答 2

0

如果想在他们的项目中使用 Robotium 框架,还应该了解 Robotium 需要两件事:

  1. 活动
  2. 包名

下一步,您需要将这些详细信息添加到清单文件中(在检测标签中)

现在挂在上面的细节上。

我们需要将这两个细节动态添加到屏幕截图记录器应用程序的清单中

这是不可能的,因为违背了清单文件的目的

本质上我是说这是一个坏主意,我们不能使用 Robotium 的“takeScreenShot”方法来拍摄屏幕截图。我建议使用ASL Library,但我仍然无法使用它。谢谢你的时间,我很抱歉浪费了别人。

于 2013-03-07T06:51:32.140 回答
0

Robotium 能够截屏,但它只包含您的应用程序的视图(例如状态栏将是空白的)。你遇到了什么问题?“我还没有太成功”什么也没说。

编辑:看来,您的项目中没有包含robotium-solo jar。

无论如何,如果您只需要它来截取屏幕截图,则根本不需要它,只需使用此代码即可,但正如我之前写的,您将需要任何视图来获取它(以及在外部存储上写入的权限)

protected void takeScreenshot(String name, View v) {
    View view = v.getRootView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    if (bmp != null) {
        String path = String.format("%s/%s/",
            Environment.getExternalStorageDirectory(),
            "scrrenshots");

        File dir = new File(path);
        if (!dir.exists()) {
            dir.mkdirs();
        }

        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(String.format(
                    "%s%s.png", path, name));
            bmp.compress(Bitmap.CompressFormat.PNG, 90, fos);
        } catch (IOException e) {
        } finally {
            if (view != null) {
                view.destroyDrawingCache();
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                }
            }
        }
    } 
}
于 2013-03-06T11:25:57.253 回答