Android Using Retrofit and OkHttp to get Endpoints - java

I have a project setup. https://github.com/Axiom1999/Iron-Banner-Companion/blob/master/app/src/main/java/me/axiom/aapp/ironbannercompanion/
And I have a button which I need to check with the API if the username on the platform exists and if it can get information then start the MainActivity intent.
I do not know how to initially start the connection.

You can use LoginActivity for checking if user already exists. Check this out in onCreate() (i think the best way keep this data in SharedPreferences). If user exists try to login and show LoginActivity with ProgressBar. If user does not exists simply show Login/SignUpActivity

Related

Android phone authentication

Getcurrentuser() return null
I facing a problem with getcurrentuser() after signout
Getinstance().signout
In phone authentication
Now currentuser return null how to overcome this?
I use phone authentication to login into the android app. Everything was working fine until when I use the "sign out" button using getinstance().signout
And after that, when I login again using phone number, I could log into the app, but now I am getting error to get current, it returns null.
How to overcome this problem? I am stuck in it.
When you call signOut() on an instance of FirebaseAuth:
Signs out the current user and clears it from the disk cache.
Which basically means that the FirebaseUser object becomes null. So what you're experiencing is normal behavior. So each time you want to use a FirebaseUser object make sure the user is authenticated. In code you should check that object against nullity. If you however want to take some action when a user signs out, then I recommend you to use an AuthStateListener, as explained in my answer from the following post:
One time login in app - FirebaseAuth

Spring browser back button handling

Using Spring 4.2.9
Web-Flow: My web-flow has three pages page-1, page-2 and error-Page
Scenario: User clicks on a link in the email, my back-end code consumes the link and user lands on a page-1(the link in the address bar now is different than what the user clicked on), the user does the required stuff on page-1 and clicks continue button and lands on page-2.
What I need when the user is on page-2:
User presses browser back button they should go to error-Page.
The user had copied the link when they were on page-1 and open a new tab and paste the page-1 link, they should land on error-page.
It's a quite common problem. A simple google search gave some possible solutions. Did you tried them? If yes, then update the question with more specifics on the issue. If not, here are a couple of links:
How to Detect Browser Back Button event - Cross Browser
Solution to browser back button click event handling
You can achieve this by configuring a Spring MVC filter (or interceptor). There you can check if the request is GET and it contains the url that you want to block. If true, you can redirect that request to the error or access denied page.
To prevent the user from resetting values when going back with the browser back button you can put a variable in the conversationScope, variables in this scope are not reverted to their previous state when you use the back button. You can this way set a variable when they reach part 2 and check for it when you load part 1, but for this to work part 1 and part 2 need to be in the same flow.
To prevent the users from using a link again, if they are authenticated users you can save a flag in the database that say they have finished the flow and simply look at the database when loading part 1 and throw an exception if the user shouldn't have access. If they are unauthenticated users (like when doing surveys), give each users a token in the url (the token should be random enough that it cannot be brute forced easily) and store it in your database, when part 1 load check that the token is in the database and when your flow is done remove the token from the database.
If you can't do any of this, you can use cookies, just send a cookie to the user when they arrive on part 2, their browser will automatically send it on any new request so if you see it on part 1 you can throw an exception. But users will be able to delete their cookies to circumvent the protection.
Changing page-2 to end-state solved the problem. The solution was mentioned in "The Definitive Guide to Spring Web Flow".
Thank you all for your help.

Why does sign-out from Leaderboard result in an application crash?

When I've signed-out from within the Leaderboards by accessing settings, and when I attempt to sign back in, the application crashes. It seems that GameHelper does not register this sign-out.
How does one fix this?
I believe this is a similar issue that was raised on the github repo. Its indicated there that its working as intended.
When you start a GPGS activity, you have to start it with startActivityForResult. If the user clicks on sign-out, the GoogleApiClient is NOT disconnected - it's just in a "signed out" state. The onActivityResult here will return a status RECONNECT_REQUIRED. At this point, the developer should reconnect their client, and life goes on as expected.
Try to modify the RECONNECT_REQUIRED condition block to disconnect, or create a way to handle it specific to your usecase (log-in page?).

Adding a custom account using Android's AccountManager

I've been trying to add a custom account to my app so I can manage the authToken to my server better, but I'm confused as to initialise eveything properly.
I've created the Authentication Activity that allows the user to log in, the Authenticator and the service, but I'm not sure how to go about handling the first time the app is opened.
The Authenticator will display the AuthActivty when it doesn't have the users account details, but in the case where the app is opened the first time, the account type doesnt exist in the phone, so I'm unable to call the getAuthToken method in the Authenticator.
Should I check if the account type exists and manually start the LoginAcivity from my MainActivty or am I missing something?
You should actually have a OOBE flow for first time launch where in you can include this.
That means, your launcher should not be main activity. Instead, it could be a spashscreen activity that can decide on whether to go to main activity or take first time launch flow

bringing up different page when logged in

let me start off by saying happy holidays to everyone!
ok i really just need confirmation and correction if needed.
what im trying to do:
Im using google and facebook "Log-in" feature to sign in for my app to retrieve the data needed like name email etc.
where i Need help:
after signing in i want another activity to be the forefront everytime app opens unless the user signs out then of course, it takes them back to the original main page to sign back in.
now im assuming this takes place in maybe the lifecycle right?
somthing like:
#override
OnResume
{
//if user is signed in cast an Intent to automatically go to another activity?
}
am i on the right track on no? thanks in advance guys
I'm not sure off the top of my head how Google and Facebook's login is implemented... do they have a sample project you're using?
And yep, you're on the right track! Generally speaking you should be able to have a "Main" activity (MainActivity for this example) which checks to see if the login was successful, and if so, kicks you to the activity you want (LoggedInActivity).
This would be in the onCreate() or onResume() method of MainActivity.java
onResume() { // onCreate() should work, too.
if (loggedIn) {
startActivity(new Intent(this, LoggedInActivity.class));
} else {
// send them to login
}
}
If there's not a good way to check if they're logged in, you could save a boolean value or api token using SharedPreferences once the login is successful, and check that value (that'd be the value of loggedIn) every time at launch. You'd obviously need to clear that value any time you logged out.

Categories