I cloned latest version of volley from https://android.googlesource.com/platform/frameworks/volley
I imported it in Eclipse, and tried to run the test project, but I get ClassNotFoundException
java.lang.NoClassDefFoundError: com.android.volley.mock.WaitableQueue$MagicStopRequest
at com.android.volley.mock.WaitableQueue.<init>(WaitableQueue.java:31)
at com.android.volley.CacheDispatcherTest.setUp(CacheDispatcherTest.java:45)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1619)
How do I run theses tests?
Thank you.
The Volley framework repo comes with support for both Ant and Gradle based build systems. Running the tests using the Gradle build system is quite simple. I did briefly try using the Ant approach, but it wasn't as straight forward and I prefer Gradle anyhow.
First thing you'll need is to install Gradle 1.10, which is the version required by Volley as of writing this answer. Alternatively, you could clone this mirror repo, which includes some extras, such as gradlew support (Gradle bootstrapping utility for downloading and using the proper version of Gradle).
Then simply execute the following command from the project root (using either gradle or gradlew based on which option you chose above):
$> gradle clean connectedCheck
This will run the full gambit of tasks, including the tests. It should produce an HTML test report at build/reports/instrumentedTests/connected/index.html, relative to the project root.
I found this to get start with.
I write this Test Project , and import com.android.volley and com.android.volley.toolbox from the volley library. And it works ^_^
public class MainActivity extends Activity {
protected static final String TAG = "com.gyh.myvolleytest";
private static Response.ErrorListener createErrorListener() {
return new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Error Response code: " + error.getMessage());
}
};
}
private static Response.Listener<String> createSuccessListener() {
return new Response.Listener<String>() {
#Override
public void onResponse(String response) {
// TODO parse response
String string = response.toString();
Log.d(TAG, "string :"+string);
}
};
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
//it is the only button in the layout ,click to log the result
public void click(View view) {
RequestQueue queue = Volley.newRequestQueue(this);
String url="http://192.168.1.108:8080/httptest/servlet/mainservlet?name=stack&age=23";
StringRequest request = new StringRequest(
Request.Method.GET,
url,
createSuccessListener(),
createErrorListener());
queue.add(request);
queue.start();
}
}
let me know what happens ^_^
Related
I am trying to build a platform agnostic communication channel between a provider and consumer processes. Found grpc + protobuf to be a good option.
Is there an example or implementation of GRPC server (Java/C++) running on Android?
I am following grpc java server example to implement the server i
private class GrpcServerTask extends AsyncTask<Void, Void, String>{
#Override
protected void onPreExecute() {
}
#Override
protected String doInBackground(Void... params) {
int port = 50051;
Server server;
try {
server = ServerBuilder.forPort(port)
.addService(new GreeterImpl())
.build()
.start();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
private class GreeterImpl extends GreeterGrpc.GreeterImplBase {
#Override
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
HelloReply reply = HelloReply.newBuilder().setMessage("Hello " + req.getName()).build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
}
}
I keep getting the error
io.grpc.ManagedChannelProvider$ProviderNotFoundException: No functional server found. Try adding a dependency on the grpc-netty artifact
on executing new GrpcServerTask().execute();
Thanks
Netty server on Android isn't really supported. Android's garbage collector and NIO support are both too poor for good Netty performance. Also some things are unlikely to work, like TLS. If it is just for testing on the newest Android release it may mostly work, but no guarantees that it works now or continues to work in the future.
With that in mind, make sure that you have a dependency on grpc-netty and try without ProGuard as a test. ProGuard's renaming and stripping both can cause trouble; you would need -keepnames io.grpc.ServerProvider and -keep io.grpc.netty.NettyServerProvider in your ProGuard rules, like was done for client-side.
C++ in another option. Client-side has been used on Android already, and I would expect server-side to function if you get client-side working. But I'm also not as aware of the C++ implementation.
Cordova can't build the project with this plugin.
When I import the project in eclipse, eclipse shows error in ParsePlugin.java
private void initialize(final CallbackContext callbackContext, final JSONArray args) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
PushService.setDefaultPushCallback(cordova.getActivity(), cordova.getActivity().getClass());
ParseInstallation.getCurrentInstallation().saveInBackground();
callbackContext.success();
}
});
}
This issue fixed by bolts-android.XXX.jar from Parse.zip
and copy it to platform/android/lib/
This question is related to How to build a Maven Android project in eclipse. Using suggestions from #user714965 I was able to build the code in project : https://github.com/nkzawa/socket.io-client.java. Now I am trying to compile an Android test project. I created a new Android project and under Java Build Path specified the socket.io-client project as dependency. But I am getting compilation errors. Eclipse is unable to find Emitter Class.
This is the relevant code:
public class SocketTask extends AsyncTask<Void, Void, Void> {
Socket mSocket = null;
#Override
protected Void doInBackground(Void... arg0) {
try {
Log.d(TAG, "Connecting to server");
mSocket = IO.socket("<my tested socket.io server address>");
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mSocket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
#Override
public void call(Object... args) {
Log.d(TAG, "Connected");
}
}).on("event", new Emitter.Listener() {
#Override
public void call(Object... args) {
Log.d(TAG, "Event");
}
}).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
#Override
public void call(Object... args) {
Log.d(TAG, "Disconnect");
}
});
mSocket.connect();
return null;
}
}
It looks like dependent libraries are not resolved. Did you install all of them correctly?
engine.io-client 0.3.0
Java-WebSocket 1.3.0
org.json 20090211 (installed in Android as default)
Emitter is included in engine.io-client.
I cannot respond to the comments (new StackOverflow user) but I have gotten the library to work in Android Studio via build.gradle. If you are primarly developing for Android they suggest moving to Android Studio as it will soon be the supported IDE.
EDIT
I can connect to a socketIO server built on nodejs from an android application with this library from nkzawa. Reference to repository.
Add library as gradle dependency:
compile 'com.github.nkzawa:socket.io-client:0.3.0'
I wrote a class to hold my socket:
public class SocketIO{
Socket sock = null;
public SocketIO(){
try{
sock = IO.socket('<connection string>');
//Place all events here as per documention
sock.on(Socket.EVENT_CONNECT, new Emitter.Listener(){
#Override
public void call(Object... args){
System.out.println("connect");
}
});
sock.connect();
} catch(URISyntaxException e){
e.printStatckTrace();
}
};
//Helper function for emiting from android
public void sEmit(String event, JSONObject obj){
if(socket.connected()){
sock.emit(event, obj);
}
}
}
And use it in my activity:
SocketIO socket = new SocketIO();
I had some initial trouble getting the library to work but it has been flawless since, the "issues" section of the github repository is very helpful.
Hope that helps.
Just starting in Android dev, I would like to use Android Websockets code in my new project in Android Studio.
OS X 10.8.x, AS 0.4.0
I followed: How to import eclipse library project from github to android studio project?
Everything worked great until I tried to actually code. I pasted in (from the example):
List<BasicNameValuePair> extraHeaders = Arrays.asList(
new BasicNameValuePair("Cookie", "session=abcd")
);
WebSocketClient client = new WebSocketClient(URI.create("wss://irccloud.com"), new WebSocketClient.Listener() {
#Override
public void onConnect() {
Log.d(TAG, "Connected!");
}
#Override
public void onMessage(String message) {
Log.d(TAG, String.format("Got string message! %s", message));
}
#Override
public void onMessage(byte[] data) {
Log.d(TAG, String.format("Got binary message! %s", toHexString(data)));
}
#Override
public void onDisconnect(int code, String reason) {
Log.d(TAG, String.format("Disconnected! Code: %d Reason: %s", code, reason));
}
#Override
public void onError(Exception error) {
Log.e(TAG, "Error!", error);
}
}, extraHeaders);
client.connect();
// Later…
client.send("hello!");
client.send(new byte[] { 0xDE, 0xAD, 0xBE, 0xEF });
client.disconnect();
When I build/run the project, I get:
error: cannot find symbol class WebSocketClient
I think my question is: What is the import statement I should use?
How would I go about adding/using this code?
You ran into a bug that was fixed in Android Studio 0.4.3. I recommend you upgrade.
The auto importer was broken. Once I restarted Android Studio it showed I should put:
import com.codebutler.android_websockets.WebSocketClient;
As my import. Now I have a NullPointerException for a particular piece of code, but that's a different problem.
What's a good pattern to use, when I want to
create the proxy entity -- works
set some properties -- works
send to GAE -- works
if the "save" button is clicked again
proxy = requestContext.edit(proxy_returned_from_server_above); // fails with "A request is already in progress"
I have spent a few days, trying many options, without any luck.
Is there a sample android app or suggestions? something that used GAE, android and GWT requestfactory?
using a "new" requestContext as some suggest does not work.
I faced the same problem. So i figured it out that you have to build the MyRequestFactory every time before call its method.
//Build this every time
MyRequestFactory requestFactory = Util.getRequestFactory(mContext,
MyRequestFactory.class);
//
final CustomRequest request = requestFactory
.customRequest();
request.queryImages().fire(
new Receiver<List<ImageProxy>>() {
#Override
public void onFailure(ServerFailure error) {
String erro = "Failure: "
+ error.getMessage();
Log.e("fail",
erro);
}
#Override
public void onSuccess(List<ImageProxy> result) {
db.importImage(result);
}
});