Reputation: 1266
I'm working with the Box API with Android. I'm using Android Studio and testing on the simulator.
I have a button that I'm using to initiate the OAuth request, after authenticating, I return to my app and a different button should show up to perform other tasks (I plan on adding get free/used/total space).
I'm using the following code, but once I return to my app, the other button doesn't show up and if I click my initial button, nothing happens.
Can anybody point me into the right direction please?
Thanks.
private void getUserIdUsingBox() {
BoxConfig.CLIENT_ID = BoxController.BOX_CLIENT_ID;
BoxConfig.CLIENT_SECRET = BoxController.BOX_SECRET;
BoxSession session = new BoxSession(this);
session.authenticate();
} //getUserIdsUsingBox
public void onLinkBox(View view) { getUserIdUsingBox(); }
private void invalidate() {
StringBuilder msg = new StringBuilder("List of available controllers: ");
for (Controller controller : mManager.getAvailableControllers()) {
msg.append("\n" + controller.getClass().getSimpleName());
}
mText.setText(msg);
List<LinkedAccount> linkedAccounts = mManager.getAvailableAccounts();
for (LinkedAccount acct : linkedAccounts) {
if (acct.getServiceName().equals(GoogleDriveController.NAME)) {
mLinkGoogleDriveButton.setVisibility(View.GONE);
mTestGoogleDriveButton.setVisibility(View.VISIBLE);
}
if (acct.getServiceName().equals(DropboxController.NAME)) {
mLinkDropboxButton.setVisibility(View.GONE);
mTestDropboxButton.setVisibility(View.VISIBLE);
}
if (acct.getServiceName().equals(BoxController.NAME))
{
mLinkBoxButton.setVisibility(View.GONE);
mTestBoxButton.setVisibility(View.VISIBLE);
}
}
}
Upvotes: 0
Views: 66
Reputation: 799
As greg mentioned -- it would be helpful to see your UI logic. But something like this should work:
final Button btnToAuthenticate = (Button) findViewById(R.id.auth_box_btn);
final Button btnAfterAuthenticate = (Button) findViewById(R.id.box_action_btn);
BoxConfig.CLIENT_ID = BoxController.BOX_CLIENT_ID;
BoxConfig.CLIENT_SECRET = BoxController.BOX_SECRET;
BoxSession session = new BoxSession(this);
btnToAuthenticate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mSession.authenticate();
}
});
mSession.setSessionAuthListener(new BoxAuthentication.AuthListener() {
@Override
public void onRefreshed(BoxAuthentication.BoxAuthenticationInfo boxAuthenticationInfo) {
}
@Override
public void onAuthCreated(BoxAuthentication.BoxAuthenticationInfo boxAuthenticationInfo) {
btnAfterAuthenticate.setVisibility(View.VISIBLE);
}
@Override
public void onAuthFailure(BoxAuthentication.BoxAuthenticationInfo boxAuthenticationInfo, Exception e) {
}
@Override
public void onLoggedOut(BoxAuthentication.BoxAuthenticationInfo boxAuthenticationInfo, Exception e) {
}
});
Upvotes: 1