re loggin using third party( google, FB,Twitter) - android

This is my first major android application, so sorry if this was asked before, but cant seem to find something relevant to help me.
I am developing an android app, where i have managed to add the google sign in method, using the google's guide. My problem now is how to enable my app, to read the users loggin information after they terminate it and relaunch it. Based on some posts here and other guides (which i cant recall now) what i did was storing a boolean variable in SharedPreferences where it states whether the user is logged in or not. boolean isLoggedIn = sharedPreferences.getBoolean(GoogleLogged, false);
I am loading the SharedPreferences file on the splash screen and make the choice of displaying the login layout or not. other than that I dont save anything else from the login process. I guess that I need to store a token, taken from the google servers, but cant find any relevant solutions.

You want to use the social login using Twitter,Fb and Google.While logging through all of these you will get different user ids as the user id for the same user for google,Fb and twitter will be different ,if you want create a user id for your users and want to use that for further communications.Get the user details from these apis like name,email and respective user id and the method of login which social medium they used for login and respective to that create a web service which will provide the user id for your usercase and store that userid in shared preferences.So in the splash screen you can check that user has logged in or not.

Related

How to login(or check if a user is already logged in ) in wordpress from my own android app

I have designed a simple android app which based on some input from the user redirects the user to certain part of my wordpress site.
The problem that I am facing is that before that, I need to check if the user is already logged in and if not to give him the possibilit to log in.
I checked around and everyone is talking about the android app but I need the login to be done from my own app.
Any idea/orientation how that can be done?
You'll need to make use of SharedPreferences which will login user at first then when the app is closed and launched again, it'll not tell the user to login. SharedPreferences will collect key values in strings and boolean then it'll save user data when the app is relaunched in the onCreate method of an Activity or in the onCreate view of a Fragment.
Remember to commit after each preference. Try to check out this YouTube playlist link:
Playlist Link
and search for SharedPreferences tutorials

When user login in one mobile, the same credientals should not login in another device in android

As I want to implement the login function same as whatsapp . If the user login in one device using (email and password) .The same login should not happen in another device.How to implement this functionality in android
In my application whenever the user login ,the status value will be change as 1 in database, when the same user if login in another device means it will show popup, already exist,If the previous user logout means value changed as 0.
But my doubt suppose if the user as logged in and uninstall the app means again he cant able to login again because the value changed as 1.
For the above situation how to handle.Please someone help me.
I am not sure, but the following idea may work.
As also mentioned here, save every users' phone ID to your DB as well. (I am also adding the code for helping you, but as I mentioned code was written by someone else in the link above)
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
Then, check if the user is trying to log in by using that device which has its ID stored in your DB. If this is the case, directly log in the user. This shows that user deleted the application without logging out.
If the user uninstalled the program in the other device and then enters the application from another device, ask the user to log in again. After user logs in, save the current device's ID in your DB. For security issues, maybe you can store the old logged in device's ID and model and more.
I hope I clearly explained to you the idea. Let me know if that helped or not.
Have a nice week!
You need to maintain session for this. when user logins create and return one sessionId for that user. for all request there after need to pass that sessionId. if same user login from another device overwrite previous sessionId with new one. so that based on that first users request will be invalid. and one user is login on one device only

Android save login user details in application

I am a web developer and new to android and studying ... For first step I made an user login system using PHP-MySQL web services.
The application communicating with the web service pretty well and check for user exists. Now if the user exists it will return the user details if user exists.
My question is like in web application is there any session / cookie handling in android application ? For eg if I can save the session then not need to login at each and every time.
I am sure there is a way to do this because lots of apps are working with this feature. But since I am new to android please advice a bit.
Not knowing a correct word to googling. Is that "SavePreferences".
Thanks in advance
I think what you are looking for is SharedPreferences. This stores data persistently in a (key, value) pair so you could say have a check box at the login screen so if they check it then it stores a boolean as the value and their username as the key. Then when they get to the login screen and choose their username it checks that value and if it is true then it doesn't require a password. This is assuming that you allow more than one user to login from the app.
However, if you only have one person logging in from the app to that device, then you could send back a value from the web server when they open the app that they can skip the login screen.
Besides the links to the docs I provided above, Here is a good example in the docs to get you started
If you are in need of something more robust than what SharedPreferences provides, then look at the Storage Options section of the docs. Hope this helps
Retrieve prefs
SharedPreferences prefs = this.getSharedPreferences("john smith", 0);
saved= (prefs.getString("loginSaved", false));
if (saved)
// do stuff here
else
// require login
SharedPreferences is what you're looking for!
Check out this code to learn more about how to use it:
http://kettiandroidproject.googlecode.com/svn/trunk/Private/Earthquake/src/com/company/earthquake/Preferences.java

Implementing oauth in android

I am new to android environment and have been trying my hands on different things in android.
I don't know whether this is possible or not, but I want to achieve some sort of functionality as follow:
when my app starts, the main activity allows the user to login using facebook or Google.
I have used Facebook SDK for login and logout functionality for facebook.
(I am still using deprecated methods)
Now when user logins using either facebook or google , I want my app to automatically navigate to other activity.
Question 1: How should I do this ? using both Facebook and Google?
This activity has four buttons. Using these , user can navigate to different parts of the App.
One of these buttons is Settings.
Whenever user clicks on this button, the App should show the profile information of the user.
The information that my First Activity gathers when it prompts the user to login.
Question 2: How should I manage user data from their accounts between different activities??
(like their email or Profile picture etc)
Question 3:
Should i access the data in first login activity or when user clicks on the "Setting " button? (in the next activity) Is it possible? how? I think I can use Access Tokens like (getAccessToken() in facebook sdk??) that i get in first activity?
Question 4:
Can i save the data when user first logs in, so that i don't have to fetch the data every time he logs in?
How should I do this?
And between one session (Login and logout) I don't want my app to fetch data everytime he user clicks on "Settings" button..... how should i save data? SharedPreferences ??
Any sort of Comments, Remarks (Related only) , Articles, tutorials, projects , views, suggestions are most welcome!!
I am quite confused.
thankyou!!
Question 1: How should I do this ?
Use an Intent to go to the next Activity on successful login.
Question 2: How should I manage user data from their accounts between
different activities?? (like their email or Profile picture etc)
Store the details in SharedPreferences when the user logs in and make sure to clear the SharedPreferences on logout.
Question 3: Should i access the data in first login activity or when
user clicks on the "Setting " button? (in the next activity) Is it
possible? how? I think I can use Access Tokens like (getAccessToken()
in facebook sdk??) that i get in first activity?
Question 4: Can i save the data when user first logs in, so that i
don't have to fetch the data every time he logs in? How should I do
this?
And between one session (Login and logout) I don't want my app to
fetch data everytime he user clicks on "Settings" button..... how
should i save data? SharedPreferences ??
Yes, SharedPreferences is the solution to these. Here is something you could do :
when the user logs in for the first time, store the access tokens and their expiry in SharedPreferences.
after that, every time, just check if the session is valid or not by using the access tokens. If session is valid, then use the details stored in your Preference file. If the session has expired, fetch the tokens again and update your SharedPreference file.
Here is an excellent video tutorial series on Android Facebook SDK and the best part for you is that he uses SDK 2.0 (the deprecated one), like you are using!

Get user data from android application

I have created an android application where user need to login to store some info like their score, level and so on which are not needed to make secured or open for all.
Now don't want to prompt user to login or sign up, My question is how my application can automatically grab users identical info like his gmail address for his android account ?
After getting the email i can send the email associating with the application result.
Thanks.
You can store information on SharedPreferences
First register and play...blah blah, done gaming, write result to SharedPreferences
Next time loading, check/read SharedPreferences whether such info/data exists then process ... blah blah
Look up info on SharedPreferences: http://developer.android.com/reference/android/content/SharedPreferences.html
There is a very good example of this in the Google IO videos, unfortunately I cannot remember which one it is.
Basically you create a UUID and store it in the shared preferences so that if it is uninstalled then it respects privacy.
That UUID is then used to key all information, if the user wishes to sign up proplery then this key is used and can later be associated with a google ID making the process completely seamless other than a single sign in.
I think it's in the 2010 videos, but I cannot remember the speaker's name.
There is a link that covers some of the basics here:
How can I get the UUID of my Android phone in an application?

Categories

Resources