how to get response code in android - android

i am using ksoap to get connected with my web services i got response code "000" as login successful on my logcat now my question is that how to handle that response code so that user can go to next page if possible please provide code..

You will need some conditional logic to programmatically decide what to do. If the user gets passed with a successful login, I would think you would want to send them to the main app screen??
if (ResponseCode == "000"){
startActivity (Intent) // where you want the user to go.
}
Else If (ResponseCode == "whateverelse"){
//Restart Login screen
}
Else {
//Your locked out or whatever other scenario you may have.
}
Something like the above will work. THere may also be additional Android login functional;ity, but I just set a boolean and pass it along with the user so I can check his login status when I may beed to.

Related

How to check facebook login status in Webview android?

I am developing an android application where i have redirected to https://m.facebook.com/ inside a web-view.
What is required?
I want to check the login status, once login is successfully done and user is on home page i want to handle visibility of some views and redirect webview to another URL which is facebook video link.
What i have tried?
I have tried checking URLs in onLoadResource and found some URLs that we get on successful login and logout. But its still not enough as Facebook login can be done via different methods (i.e by number, by email, by already saved account etc).
To check Logout:
fun isFacebookLoggedOut(url: String?): Boolean {
return url?.startsWith("https://m.facebook.com/?stype=lo&jlou")!!
}
To check Login:
fun isFacebookLoggedIn(url: String?): Boolean {
if (url.equals("https://m.facebook.com/login/save-device/?login_source=login#_=_") || url.equals(
"https://m.facebook.com/login/save-device/cancel/?flow=interstitial_nux_retry&nux_source=regular_login"
) || url?.contains("https://m.facebook.com/login/device-based/validate-pin/?refid=")!!
|| url.startsWith("https://m.facebook.com/login/device-based/login/async/?") || url.startsWith(
"https://m.facebook.com/login/account_recovery/name_search/?flow=initiate_view&ls=initiate_view"
)
) {
return true
} else {
return false
}
}
This works in some cases and on some devices but there are scenarios when user log in with contact number, or saved account which goes through different phases like entering credentials then verifying any code if browser is new and so on.
Is there any method or proper way to track login status thats perfect for each scenario and each device?
Can somebody please help me out with this.
Any help will be appreciated
You can visit this link to have all the detailed information to implement the Facebook SDK and be able to login to Facebook throught your app.

Firebase SDK Auth Package Trouble with Automatically Loading Scene Once Authenticated Unity

I am stuck with a functionality of the Firebase SDK (Auth package) regarding the Scenes and it's integration. Here's how they work:
1st: Loading Scene
Here, I just added the FirebaseInit code EXACTLY as suggested by Patrick, which it's only function is to call the next scene (Login/Register) once everything loads correctly.
2nd: Login/Register Scene
Here I do all the Login AND ALSO the register logic. I set up a button that alternates between the two (Activating the respective parent gameObject within the Canvas). Once the user log's in, the 3rd scene comes into play.
3rd: App's Main Screen Scene
Main Screen of the app, where the user can LOGOUT and return to the Login Scene.
Problem
I added the 'LoadSceneWhenUserAuthenticated.cs' in the 2nd Scene, and it works (kind of).
It actually does what it is supposed to. If I log in, quit the game without loging out, and open it again, it does come back directly to the 3rd scene. BUT some things are happening and they aren't supposed to.
First
When I Sign Up a user, I call the method 'CreateUserWithEmailAndPasswordAsync()'. Once it completes, it should activate the login screen and stay there, waiting for the user to fill in the password, but the 'FirebaseAuth.DefaultInstance.StateChanged' comes into play and forces the 3rd screen to be loaded, skipping several other steps that should be taken (email registration for example).
Second
As I mentioned in the end of number 1 above, if I try to log in to an account that does not have it's email verified, it works! (due to the 'LoadSceneWhenUserAuthenticated.cs' which is added in the scene). Code:
var LoginTask = auth.SignInWithEmailAndPasswordAsync(_email, _password);
LoginTask.ContinueWithOnMainThread(task =>
{
if (task.IsCanceled || task.IsFaulted)
{
Firebase.FirebaseException e =
task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException;
GetErrorMessage((AuthError)e.ErrorCode, warningLoginText);
return;
}
if (task.IsCompleted)
{
User = LoginTask.Result;
if (User.IsEmailVerified == true)
{
UIControllerLogin.instance.MainScreenScene();
}
else
{
warningLoginText.text = Lean.Localization.LeanLocalization.GetTranslationText($"Login/VerifyEmail");
}
I know that it's possible to fix this issue by adding an extra scene just before the login scene (as Patrick does in the youtube video) but it doesn't make any sense in my app. It would actually only harm the UX of it.
Patrick's Video:
https://www.youtube.com/watch?v=52yUcKLMKX0&t=264s
I'm glad my video helped!
My architecture won't work for every game, and I tried to boil it down to the bare minimum to get folks started. You may be able to get the functionality you want by adding an additional check in HandleAuthStateChanged:
private void HandleAuthStateChanged(object sender, EventArgs e)
{
if (_auth.CurrentUser != null && !_auth.CurrentUser.IsAnonymous && _auth.CurrentUser.IsEmailVerified)
{
SceneManager.LoadScene(_sceneToLoad);
}
}
but it does sound like, at this point, you'll want to build out a more robust registration/sign in flow that fits your use case.
If you need more help, I might suggest re-posting on the community mailing list or the subreddit. Those resources may be more better suited to discussing various pros/cons of different architectures or spitballing ideas (and feel free to link to any new posts in a comment so myself or others interested can follow along).

AppAuth Relogin

After some back and forth I finally got this to work but I had to use version 0.2.0 because I followed the google guide presented in the Readme.
Anyway, Im struggling with handling what will happen when the oAuth token times out. Then it needs to open the browser again to log in or is there a background process available for this as it automatically redirects back to the app because the server remembers the user so there is no need for a new username/password input?
Im getting a refresh token like this :
if(mAuthService == null){
mAuthService = new AuthorizationService(context);
}
mAuthState.performActionWithFreshTokens(mAuthService, new AuthState.AuthStateAction() {
#Override public void execute(
String accessToken,
String idToken,
AuthorizationException ex) {
if (ex != null) {
return;
}
// Getting the access token...
}
});
Thats working fine but after the user is idle for some time it wont work. How to handle this properly?
Solution for my problem was this:
I changed to using offline_access for the token in the scope. Depending on the site/service you're login into if they accept it or not. For me it was accepted and will keep the user logged in for a long time and removes the need to re-login.

WebDialog.RequestsDialogBuilder does not actually send a request?

I am working on an app, which sends a request to the selected user. Am selecting the user through FriendPickerFragment(Android.Support.V4.App). I am successfully getting the list of friends I have selected on the "Done" button of the Picker fragment. Post that, I am trying to build a request dialog, which should not show up in my app, but should send the FB request to the selected friends. Here is my code:
Bundle bundle = new Bundle ();
bundle.PutString ("app_id", AppID);
var dialog = new WebDialog.RequestsDialogBuilder (this.Activity, Session.ActiveSession, bundle).SetMessage(user + " has invited you to join my application");
dialog.Build ();
The problem I am facing is that, the request is not actually sent. There is no exception either. I even implemented the call back:
public void OnComplete(Bundle bundle, FacebookException e)
but the execution does NOT go in the callback. What am I missing here ? Any help would be greatly appreciated.
Tried dialog.SetTo(userId) before build also....still not working...
Any suggestions ?
Well, according to the documentation for RequestDialogBuilder the method public WebDialog build(), the behavior you describe is by design. Quote:
"The dialog is not shown, but is ready to be shown by calling Dialog.show()"
It sounds like you do not want to show a dialog, but just want to send a request without any UI. You are using the wrong tool to do that. To send a request using a dialog, you have to show the dialog, and the user action is what causes a request to be sent. This doesn't require any special permission to be granted ahead of time, because it only sends a request if the user chooses to after your app opens the dialog.
There may or may not be a way to do what you want (send an app request without any user interaction) ... if there is a way, it will be along these lines:
use the Graph API, get a token with some permission that the user grants to your app. Here's a place to start looking:
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/apprequests/

Parse for Android : ParseUser.logOut() doesn't log user out

I've been playing around with Parse on Android for a few days, I have a problem with ParseUser.logOut() => it actually doesn't log the current user out.
Here's what I do :
private void onClickOnDisconnect() {
ParseUser.logOut();
currentUser = ParseUser.getCurrentUser(); // should be null but isn't...
invalidateOptionsMenu();
Toast.makeText(getApplicationContext(), "Disconnected...", Toast.LENGTH_LONG).show();
}
After the call to ParseUser.logOut(), ParseUser.getCurrentUser() should return null (says the documentation). Still it returns the previously logged in user.
Even though I restart the app the user is still considered as connected.
I use parse framework v1.3.8 (downloaded a 3 days ago). I don't use Facebook SDK, as I've seen a few questions for that specific case.
Thanks in advance
Somewhere in your app, probably the appDelegate you most likely send this message to the PFUserClass
[PFUser enableAutomaticUser];
in this case the
[PFUser currentUser];
will never return nil;
I had the same issue while incorporating logout functionality with facebook login. The error turned out to quite simple and a basic mistake on my part. I had written the following piece of code in my Application class
ParseUser.enableAutomaticUser();
This creates the user every time you run your application even if you have logged out the last time around. Removing this solved my problem.
As I said in the comments above, I got it to work by :
uninstalling the app
deleting the user on the Parse dashboard
reinstalling the app and signing up again
Then the signout/signin mechanism worked miraculously :|
The only reason I can imagine is that I had previously signed up with this user having Automatic user creation enabled, and it somehow stuck to the user entity in Parse.
Experiencing same bug. Now instead of only checking ParseUser as null, I check username too:
ParseUser currentUser=ParseUser.getCurrentUser()
if(currentUser==null)
{
//user doesn't exist
}
else
{
if(currentUser.getUserName()==null)
{
//user oesn't exist
}
}
Try
ParseUser.getCurrentUser().logOut();
I had the same problem. Actually it was a bug in parse sdk and the problem was solved without changing any of my code, just by installing the latest parse android sdk(1.8.1 at the time of writing).
I had the same issue it was because i has automatic user enabled which causes a new anonymous user to be created, it is also explained here
https://www.parse.com/questions/issues-with-parseuserlogout-on-android
Try to logout the current user object, not the class.
ParseUser.getCurrentUser().logout();
and make sure to delete
ParseUser.enableAutomaticUser();
Edit:
When you logout, the User instance will still available, but with null fields. Parse changes all the user's fields into nulls.
So, if you want to check whether the user is logged in or out, just do the following
if(ParseUser.getCurrentUser().getUsername() == null)
{ // user is out
} else {
// user is in }

Categories

Resources