I have a Vert.X SockJS server running using the following code:
HttpServer httpServer = vertx.createHttpServer();
SockJSServer sockJSServer = vertx.createSockJSServer(httpServer);
JsonObject config = new JsonObject().putString("prefix", "/echo");
sockJSServer.installApp(config, new Handler<SockJSSocket>() {
public void handle(SockJSSocket sock) {
Pump.createPump(sock, sock).start();
}
});
httpServer.listen(8080);
Now I need to send messages from the server to an Android (and vice versa) application and I have no idea how to set that up on the client. The documentation talks about handling that in JavaScript but on the browser.
UPDATE: I believe the following code is a bit in the right direction. I still need to add the host ip address (not sure how).
public void start() {
SockJSSocket client = new SockJSSocketBase(vertx){
#Override
public boolean writeQueueFull(){
// TODO Auto-generated method stub
return false;
}
#Override
public SockJSSocket setWriteQueueMaxSize(int arg0){
// TODO Auto-generated method stub
return null;
}
#Override
public SockJSSocket drainHandler(Handler<Void> arg0){
// TODO Auto-generated method stub
return null;
}
#Override
public SockJSSocket write(Buffer arg0){
// TODO Auto-generated method stub
return null;
}
#Override
public SockJSSocket exceptionHandler(Handler<Throwable> arg0){
// TODO Auto-generated method stub
return null;
}
#Override
public SockJSSocket resume(){
// TODO Auto-generated method stub
return null;
}
#Override
public SockJSSocket pause(){
// TODO Auto-generated method stub
return null;
}
#Override
public SockJSSocket dataHandler(Handler<Buffer> arg0){
// TODO Auto-generated method stub
return null;
}
#Override
public SockJSSocket endHandler(Handler<Void> arg0){
// TODO Auto-generated method stub
return null;
}
};
}
I think you can try a different way, if you want your android app to talk to a vertx server: using websocket, it is easier than using sockjs to setup a connection between them. Because I met and solved a similar requirement not long ago.
Because websocket connection is a two-way channel, which means a vertx app could send text to your android app and vice versa. At the same time, there is Java-WebSocket(http://java-websocket.org/) which you can use for your android app. It is very easy to use.
Also, to set up a websocket handler in vertx is not hard, there are many examples in document.
Related
I am trying to show flurry interstitial but getting following message in debug screen and I am not receiving interstitial on my screen.
07-14 15:55:31.390: W/webview(10588): java.lang.Throwable: Warning: A
WebView method was called on thread 'FlurryAgent'. All WebView methods
must be called on the UI thread. Future versions of WebView may not
support use on other threads.
I have followed this tutorial completely :
Android Integration
At present I am working on AndEngine. As error replying I put my all code in UI thread but result is same.
Here is my code for displaying ads :
protected void onCreate(Bundle pSavedInstanceState) {
super.onCreate(pSavedInstanceState);
// configure Flurry
FlurryAgent.setLogEnabled(false);
// init Flurry
FlurryAgent.init(MainGameActivity.this, MY_FLURRY_APIKEY);
mFlurryAdInterstitial = new FlurryAdInterstitial(MainGameActivity.this,
MY_ADSPACE_NAME);
FlurryAdTargeting adTargeting = new FlurryAdTargeting();
// enable test mode for this interstitial ad unit
adTargeting.setEnableTestAds(true);
mFlurryAdInterstitial.setTargeting(adTargeting);
// allow us to get callbacks for ad events
mFlurryAdInterstitial.setListener(interstitialAdListener);
mFlurryAdInterstitial.fetchAd();
}
FlurryAdInterstitialListener interstitialAdListener = new FlurryAdInterstitialListener() {
#Override
public void onFetched(final FlurryAdInterstitial adInterstitial) {
adInterstitial.displayAd();
}
#Override
public void onError(final FlurryAdInterstitial adInterstitial,
FlurryAdErrorType adErrorType, int errorCode) {
adInterstitial.destroy();
}
#Override
public void onAppExit(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onClicked(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onClose(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onDisplay(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onRendered(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onVideoCompleted(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
};
#Override
protected void onStart() {
super.onStart();
FlurryAgent.onStartSession(MainGameActivity.this);
}
#Override
protected void onStop() {
super.onStop();
FlurryAgent.onEndSession(MainGameActivity.this);
}
#Override
public void onDestroy() {
super.onDestroy();
mFlurryAdInterstitial.destroy();
}
So what can I do in this situation?
I am integrating Game Circle SDK & Whisper Sync in my game. I have implemented the code, but it has caused an issue. When I load the game and get the game state from the WhisperSync and set my local variables, white patches are observed in some places randomly instead of the proper image. When I turn of GameCircle & Whisper Sync it runs fine.
My game is developed using Cocos2d Android.
Does any one encountered such issue?
I have attached the image for reference.
Some Code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
CCGLSurfaceView _glSurfaceView = new CCGLSurfaceView(this);
setContentView(_glSurfaceView);
CCDirector.sharedDirector().attachInView(_glSurfaceView);
CCDirector.sharedDirector().setDisplayFPS(false);
CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f);
CCScene scene = IntroLayer.scene();
CCDirector.sharedDirector().runWithScene(scene);
}
#Override
public void onResume() {
super.onResume();
if (IS_AMAZON) {
AmazonGamesClient.initialize(this, callback, myGameFeatures);
AmazonGamesClient.getWhispersyncClient()
.setWhispersyncEventListener(
new WhispersyncEventListener() {
#Override
public void onAlreadySynchronized() {
// TODO Auto-generated method stub
super.onAlreadySynchronized();
System.out
.println("FA here onAlreadySynchronized");
loadGameScene();
}
#Override
public void onDataUploadedToCloud() {
// TODO Auto-generated method stub
super.onDataUploadedToCloud();
System.out
.println("FA here onDataUploadedToCloud");
}
#Override
public void onDiskWriteComplete() {
// TODO Auto-generated method stub
super.onDiskWriteComplete();
System.out
.println("FA here onDiskWriteComplete");
}
#Override
public void onFirstSynchronize() {
// TODO Auto-generated method stub
super.onFirstSynchronize();
System.out
.println("FA here onFirstSynchronize");
loadGameScene();
}
#Override
public void onNewCloudData() {
// TODO Auto-generated method stub
super.onNewCloudData();
System.out
.println("FA here onNewCloudData");
}
#Override
public void onSyncFailed(FailReason reason) {
// TODO Auto-generated method stub
super.onSyncFailed(reason);
System.out
.println("FA here onSyncFailed reason: "
+ reason.name());
}
#Override
public void onThrottled() {
// TODO Auto-generated method stub
super.onThrottled();
System.out.println("FA here onThrottled");
}
});
Log.i(TAG, "onResume: call initiateGetUserIdRequest");
PurchasingManager.initiateGetUserIdRequest();
Log.i(TAG, "onResume: call initiateItemDataRequest for skus: "
+ LAppInfo.getInstance().getList());
Set<String> skus = new HashSet<String>(LAppInfo.getInstance()
.getList());
PurchasingManager.initiateItemDataRequest(skus);
}
CCDirector.sharedDirector().resume();
}
private AmazonGamesCallback callback = new AmazonGamesCallback() {
#Override
public void onServiceNotReady(AmazonGamesStatus status) {
// unable to use service
System.out.println("FA here callback onServiceNotReady: "
+ status.name());
}
#Override
public void onServiceReady(AmazonGamesClient amazonGamesClient) {
System.out.println("FA here callback onServiceReady: ");
agsClient = amazonGamesClient;
}
};
private void loadGameScene() {
LoadData();
CCScene mainMenu = LevelMenuScene.scene();
CCDirector.sharedDirector().replaceScene(
CCFadeTransition.transition(0.5f, mainMenu));
}
Solved it by a work around by having a boolean variable and set it to true after the data is loaded in firstsync/alreadysync method. and loading the scene in the main thread instead of the callback of whispersync. Will be glad to know if some one find a proper solution.
I have implemented Twilio thrid party SDK for making outgoing calls in android. When i make a call when the number is switched off or refused the call gets disconnected after some time automatically i have been trying to fetch this event.To fetch this event i tried implementing The ConnectionListener interface and has override all the method but when the call gets disconnected or connected i was not able to get any logs printed. After implementing the ConnectionListener i have implemented the following method in my code.
#Override
public void onConnected(Connection arg0) {
// TODO Auto-generated method stub
Log.i("test", "onconnected");
}
#Override
public void onConnecting(Connection arg0) {
// TODO Auto-generated method stub
Log.i("test", "onconnecting");
}
#Override
public void onDisconnected(Connection arg0) {
// TODO Auto-generated method stub
Log.i("test", "onDisconnected");
}
#Override
public void onDisconnected(Connection arg0, int arg1, String arg2) {
// TODO Auto-generated method stub
Log.i("test", "onDisconnected");
}
Can anyone help me on this issue. Thank in advance.
check if you have callbacks to notify your app of outgoing connections.
you should have something like this:
connection = device.connect(params, this);
Just implementing the override functions of Connection listener is not sufficient.
But you need to set the listener to the connection. Like
either
connection = device.connect(parameters, this /* ConnectionListener */);
or
connection.setConnectionListener(this /*ConnectionListener */);
Hope this helps...
I tried this How can I develop a custom "non-fullscreen" softkeyboard for tablets? to make it full screen mode but still its not full screen :(
And also i have tried the following in my code
#Override
public boolean onEvaluateFullscreenMode() {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isFullscreenMode() {
// TODO Auto-generated method stub
return true;
}
#Override
public void setExtractViewShown(boolean shown) {
// TODO Auto-generated method stub
super.setExtractViewShown(true);
}
Not working as expeced, can any one help me to solve this ?
overide the following two methods from InputmethodService as bellow
#Override
public void onUpdateExtractingVisibility(EditorInfo ei) {
// TODO Auto-generated method stub
setExtractViewShown(true);
}
#Override
public boolean onEvaluateFullscreenMode() {
return true;
}
This worked for me :)
Hey im trying to add countdown timers to an arraylist but it is crashing. It is crashing once I try to add one countdowntimer . Was wondering is there anything I could do to fix it?
ArrayList<CountDownTimer> timers;
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
toggleLock.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Checker = new CountDownTimer(1200000, 60000)
{
#Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
//does stuff
}
#Override
public void onFinish() {
// TODO Auto-generated method stub
}
};
Checker.start();
timers.add(Checker);
}
}
});
}
I think you need to initialize the arraylist, so might be throwing null pointer exception.
timers=new ArrayList<CountDownTimer>();
You need to initialize your timers arraylist.
ex.
ArrayList<CountDownTimer> timers = new ArrayList<CountDownTimer>();