How to pass realm in AutobahnConnection android? - android

I am using AutobahnConnection for ws communication. I have created the object of AutobahnConnection and passed the wsUri but I am unable to find a way to pass "realm" with it. It is compulsory for me to pass it. I have explored lot of places but I am unable to find any solutions. Here is my code
private final AutobahnConnection mConnection = new AutobahnConnection();
private void start() {
final String wsUri = "ws://xxx.xxx.xxxx/ws";
mConnection.connect(wsUri, new Autobahn.SessionHandler() {
#Override
public void onOpen() {
testRpc();
testPubSub();
}
#Override
public void onClose(int code, String reason) {
Log.d(TAG, "calc:add result = " + reason);
}
});
}`
I am getting Protocol Voilation Error as I am ubable to pass realm. Any help will be highly appreciated.

What are you trying to connect to? AutobahnAndroid only does WAMP v1, which is incompatible with WAMP v2. To connect to v2 routers from Android, you may want to take a look at https://github.com/Vinelab/Android-wamp-client.

Related

LibGDX http request not working

I want to send a String message to database when user presses a specific button in the LibGDX game I am designing for android. How do I go about doing that? Following is the code I tried. But it does not work.
Net.HttpRequest httpRequest = new Net.HttpRequest();
httpRequest.setMethod("POST");
httpRequest.setUrl("URL is here");
httpRequest.setContent("INSERT INTO `game_table` (`Button`) VALUES ('Button 1 Pressed')");
Net.HttpResponseListener httpResponseListener = new Net.HttpResponseListener() {
#Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
Gdx.app.log("Log httpResponse", httpResponse.getResultAsString());
}
#Override
public void failed(Throwable t) {
}
#Override
public void cancelled() {
}
};
Gdx.net.sendHttpRequest(httpRequest,httpResponseListener);
Log does not provide anything in android monitor. I also tried using AsyncTask and without AsyncTask to implement this code. But neither works.
Am I missing something? If so could you give me small code snippet that will work?
You don't need to use an AsyncTask, libGDX' HTTPRequest is async out of the box.
You did not log anything if the request fails or is cancelled so probably that's the case.

OneDrive SDK for android, cannot login silently

I have a standalone Java application that uses a OneDrive Java API I found on github. Everything works nicely.
So I already have a clientid, a client secret, an authorization code and a refresh token which work flawlessly
Now I wanted to switch over to Android, but I wasn't successfull in using the same Java API. That's why I wanted to move to the official OneDrive Android SDK provided by Microsoft.
Everything seems to be different there. I tried the following, using my already known clientid
final Activity me = this;
final MSAAuthenticator msaAuthenticator = new MSAAuthenticator() {
#Override
public String getClientId() {
return clientid;
}
#Override
public String[] getScopes() {
return new String[] { "onedrive.appfolder" };
}
};
final IClientConfig oneDriveConfig = DefaultClientConfig.createWithAuthenticator(
msaAuthenticator);
final IOneDriveClient oneDriveClient = new OneDriveClient.Builder()
.fromConfig(oneDriveConfig)
.loginAndBuildClient(me);
oneDriveClient
.getDrive()
.buildRequest()
.get(new ICallback<Drive>() {
#Override
public void success(final Drive result) {
final String msg = "Found Drive " + result.id;
Toast.makeText(me, msg, Toast.LENGTH_SHORT)
.show();
}
#Override
public void failure(ClientException ex) {
final String msg = "Error";
Toast.makeText(me, msg, Toast.LENGTH_SHORT)
.show();
}
});
It ends up in a seemingly endless loop while executing the line .loginAndBuildClient(me)
In logcat I see that it suppressed an Exception
07-13 12:32:17.082 28175-28271/org.xxxxxxx.xxxxxxxxx E/MSAAuthenticator$5[onAuthComplete] - 314:
Failed silent login, interactive login required
com.onedrive.sdk.authentication.ClientAuthenticatorException: Failed silent login, interactive login required
at com.onedrive.sdk.authentication.MSAAuthenticator$5.onAuthComplete(MSAAuthenticator.java:312)
There are also some info messages:
07-13 12:32:17.079 28175-28271/org.xxxxxxx.xxxxxxxxx I/LiveAuthClient:
No refresh token available, sorry!
07-13 12:32:17.079 28175-28271/org.xxxxxxx.xxxxxxxxx I/LiveAuthClient:
All tokens expired, you need to call login() to initiate interactive logon
Obviously it somehow wants to perform an interactive login and fails terribly.
What I don't understand: I already have a perfectly valid refresh token which I want to reuse, but I did not find a way to do it in the MS OneDrive SDK.
Can someone help me here?
This post is a little old, but i wanted to share my solution to help others.
Instead of using this method "loginAndBuildClient" with only the Activity parameter, like this :
final IOneDriveClient oneDriveClient = new OneDriveClient.Builder()
.fromConfig(oneDriveConfig)
.loginAndBuildClient(me);
Declare a global OneDriveClient:
private IOneDriveClient mOneDriveClient;
Then use the "loginAndBuildClient" method with the Callback parameter. And assign your OneDriveClient in the "success" method :
new OneDriveClient.Builder()
.fromConfig(DefaultClientConfig.createWithAuthenticator(msaAuthenticator))
.loginAndBuildClient(MainActivity.this, new ICallback<IOneDriveClient>() {
#Override
public void success(IOneDriveClient iOneDriveClient) {
mOneDriveClient = iOneDriveClient;
}
#Override
public void failure(ClientException ex) {
mOneDriveClient = null;
}
});
I managed to implement access to the OneDrive API manually (without using the SDK) and it worked
Turns out I "only" forgot to set INTERNET permission for the app. Really strange that it caused my app to fail silently.

AndroidAsync Socket.IO receive callback value

I'm trying to build an application for Android using this library: https://github.com/koush/AndroidAsync and I was trying to receive a callback value from the server like this but the app crashes:
client.emit("callbackTry", new Acknowledge() {
#Override
public void acknowledge(JSONArray arg0) {
Log.e(TAG,"acknowledge: "+ arg0);
}
});
I leave you the server-side:
socket.on('callbackTry', function (callback) {
console.log(callback);
var hello = "Hello";
callback(hello);
});
How can I return the data back to the client?
I found a solution myself which consists on changing emit method to emitEvent. Hope it really help someone else too.

One of my Application's view inside my second application in android

I got stuck in to the problem where I need to show my first application in to some area of second application's screen. Both codes are under my control. Can any one suggest me where should I proceed as I am not getting any clue about the situation.
if some one help me for the issue, it would be a great help for me.
Or
If I can open both of my applications using the multiscreen option available in S3.
Write a service on either of your application or a individual application. Have AIDL(Android Interface Definition Language) defined as IRemoteService.aidl, the below is my pseudo code or sample implementation. Using this approach you can start activity and handle events of another application through your application.
// IRemoteService.aidl
// Declare any non-default types here with import statements
/** Example service interface */
interface IAccountService {
String getLoggedInUserInfo(String appId);
void userLogin(String appId,ILoginCallback cb);
void signout(String appId);
}
interface ILoginCallback {
void loginSuccess(String userId);
void loginFailed();
}
In your service have some RemoteCallbacks
#Override
public IBinder onBind(Intent intent) {
final RemoteCallbackList<ILoginCallback> mCallbacks = new RemoteCallbackList<ILoginCallback>();
if(mCallbacks!=null){
int i = mCallbacks.beginBroadcast();
while(i>0){
i--;
try {
Log.e(TAG, "Callback ...");
mCallbacks.getBroadcastItem(i).loginSuccess(newUserId);
} catch (RemoteException e) {
// The RemoteCallbackList will take care of removing
// the dead object for us.
}
}
mCallbacks.finishBroadcast();
}
}
private final IAccountService.Stub mBinder = new IAccountService.Stub() {
#Override
public void userLogin(String appId,ILoginCallback cb) throws RemoteException {
String userId = Settings.getSettings().getUserId();
if(userId ==null||userId.length()==0){
mCallbacks.register(cb);
Intent intent = new Intent(getApplicationContext(), AccountLoginActivity.class);
intent.putExtra("deviceId", Settings.getSettings().getDeviceUniqueId());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}
You can find detailed AIDL examples in the below links.
http://owenhuangtw.pixnet.net/blog/post/23760257-android-aidl-(android-interface-definition-language)
http://www.app-solut.com/blog/2011/04/using-the-android-interface-definition-language-aidl-to-make-a-remote-procedure-call-rpc-in-android/
https://github.com/afollestad/aidl-example

Unlocking achievement in OpenFeint

I'm very new to OpenFeint, actually started integrating it into my game today. I can't understand one simple thing that every OpenFeint using developer should probably know. Here's the example of unlocking an achievement from OpenFeint official tutorial:
new Achievement("achievementID").unlock(new Achievement.UnlockCB () {
#Override public void onSuccess() {
MyClass.this.setResult(Activity.RESULT_OK);
MyClass.this.finish();
}
#Override public void onFailure(String exceptionMessage) {
Toast.makeText( MyClass.this,
"Error (" + exceptionMessage + ") unlocking achievement.",
Toast.LENGTH_SHORT).show();
MyClass.this.setResult(Activity.RESULT_CANCELED);
MyClass.this.finish();
}
});
Problem is that I don't want to finish my activity in onSuccess or onFailure, I just don't need to do anything here. If I just leave these two methods codeless, my game freezes an becomes totally unresponsive. What should I do? Thanks in advance.
P.S. How do you create Test Users? I've tryed every email-password combination possible and could not get it to go..
Its generally a good idea to put all your communication with the internet in a AsyncTask. Not everyone has fast internet, so this will make sure the main thread doesn't lock up because of that.
That being said, I think that the setResult function is used in a startActivityForResult construction. The intent that is created in this way is only sent back to the original class if the activity is finished. So to fix this you would need to put the code in a separate activity.
I simply wrote this method in my Utility class
public static void unlockAchievement(final String achievementId, final Activity context){
final Achievement achievement = new Achievement(achievementId);
achievement.unlock(new Achievement.UnlockCB() {
#Override
public void onSuccess(boolean newUnlock) {
context.setResult(Activity.RESULT_OK);
}
#Override
public void onFailure(String exceptionMessage) {
context.setResult(Activity.RESULT_CANCELED);
Toast.makeText(context, "Error (" + exceptionMessage + ") unlocking achievement.", Toast.LENGTH_SHORT).show();
FlurryAgent.onError("unlockingAchievement", exceptionMessage, this.getClass().getSimpleName());
}
});
}

Categories

Resources