ViewServer is a simple class you can use in your Android application
to use the HierarchyViewer inspection tool.
ViewServer requires the Android SDK r12 or higher.
http://developer.android.com/sdk/index.html
Please refer to the documentation in ViewServer.java for more info.
[url]https://github.com/romainguy/ViewServer[/url]
[size=medium][color=red][b]Enable HierarchyViewer on production builds[/b][/color][/size]
For security reasons HierarchyViewer does NOT work on production builds. It works only with userdebug and engineering builds (this includes the emulator.)
In this case you’ve got the following errors:
[hierarchyviewer]Unable to get view server protocol version from device
[hierarchyviewer]Unable to debug device
But there is a way to enable the use of HierarchyViewer inside your own application. Romain Guy suggests to use ViewServer class: https://github.com/romainguy/ViewServer
The recommended way to use this API is to register activities when they are created, and to unregister them when they get destroyed:
public class MyActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set content view, etc.
ViewServer.get(this).addWindow(this);
}
public void onDestroy() {
super.onDestroy();
ViewServer.get(this).removeWindow(this);
}
public void onResume() {
super.onResume();
ViewServer.get(this).setFocusedWindow(this);
}
}
To use this view server, your application must require the INTERNET permission:
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
As a result you will be able to make HierarchyViewer work on any devices:
[img]http://dl.iteye.com/upload/attachment/0081/1806/eb316b94-40e7-3d42-b61b-21b17ea7b6ac.png[/img]
Sometimes it could be useful to build ViewServer as Library project, as described at: http://developer.android.com/tools/projects/projects-eclipse.html
And then just referencing it from your application like this:
[img]http://dl.iteye.com/upload/attachment/0081/1808/6788679b-48d5-3592-93ab-d496347f7004.png[/img]
And once again: do not forget to add INTERNET permission! Otherwise you will got some NullPointerExceptions with ServerSocket.
to use the HierarchyViewer inspection tool.
ViewServer requires the Android SDK r12 or higher.
http://developer.android.com/sdk/index.html
Please refer to the documentation in ViewServer.java for more info.
[url]https://github.com/romainguy/ViewServer[/url]
[size=medium][color=red][b]Enable HierarchyViewer on production builds[/b][/color][/size]
For security reasons HierarchyViewer does NOT work on production builds. It works only with userdebug and engineering builds (this includes the emulator.)
In this case you’ve got the following errors:
[hierarchyviewer]Unable to get view server protocol version from device
[hierarchyviewer]Unable to debug device
But there is a way to enable the use of HierarchyViewer inside your own application. Romain Guy suggests to use ViewServer class: https://github.com/romainguy/ViewServer
The recommended way to use this API is to register activities when they are created, and to unregister them when they get destroyed:
public class MyActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set content view, etc.
ViewServer.get(this).addWindow(this);
}
public void onDestroy() {
super.onDestroy();
ViewServer.get(this).removeWindow(this);
}
public void onResume() {
super.onResume();
ViewServer.get(this).setFocusedWindow(this);
}
}
To use this view server, your application must require the INTERNET permission:
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
As a result you will be able to make HierarchyViewer work on any devices:
[img]http://dl.iteye.com/upload/attachment/0081/1806/eb316b94-40e7-3d42-b61b-21b17ea7b6ac.png[/img]
Sometimes it could be useful to build ViewServer as Library project, as described at: http://developer.android.com/tools/projects/projects-eclipse.html
And then just referencing it from your application like this:
[img]http://dl.iteye.com/upload/attachment/0081/1808/6788679b-48d5-3592-93ab-d496347f7004.png[/img]
And once again: do not forget to add INTERNET permission! Otherwise you will got some NullPointerExceptions with ServerSocket.