Firebase createUser() does not create user - android

I am trying to play around with Firebase, I have this piece of code but the user is not getting created.
I've enabled email and password auth on Firebase. The Firebase url is correct.
public class RegisterActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
Firebase.setAndroidContext(this);
Button BCreate;
BCreate=(Button)findViewById(R.id.Createbutton);
BCreate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.e("URL", "Before firebase url");
go();
}
});
}
private void go() {
final Firebase ref=new Firebase("https://testingbasee.firebaseio.com");
Log.e("GOOOOOO!", "gooooooo!");
ref.createUser("aa#bb.com", "12345", new Firebase.ResultHandler() {
#Override
public void onSuccess() {
Log.e("GOOOOOO!","gooooooo!");
}
#Override
public void onError(FirebaseError firebaseError) {
Log.e("NOPOOOOOOOO!","noooo!!1!");
}
});
}
}

Related

How to start another activity when value is added in Firebase

I'd like to start another activity when a value is added in the database of Firebase.
No error is appearing but when I add a value in the database nothing happens.
Here's my sample code. I've been searching for the past days but it is my first app and I'm a bit confused.
DatabaseReference databaseReference;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blackscreen);
databaseReference = FirebaseDatabase.getInstance().getReference();
}
#Override
protected void onStart() {
super.onStart();
usingFirebaseDatabase();
}
public void usingFirebaseDatabase() {
databaseReference.child("uploads")
.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
do {
if (dataSnapshot.exists()) {
Intent intent = new Intent(blackscreen.this,MainActivity.class);
startActivity(intent);
} else {
return;
}
} while (!dataSnapshot.exists());
}
#Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(blackscreen.this, "NO images found \n" + databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}

how to write a variable from a singleton in firebase

There is a program where I can change a variable using a singleton. Created 2 activites, where users can change this variable. How to write the variable that is being changed to the Firebase database. I tried to use the addValueEventListener (new ValueEventListener () method.
Where do I use the firebase methods? In the main class or in singleton? And how to write a variable?
main activity
public class MainActivity extends AppCompatActivity {
private BubbleWrap bubbleWrap;
private TextView txtintent;
final int REQUEST_CODE_661_1 = 1;
private int bbbbb;
private TextView txt;
private String bubul;
FirebaseDatabase database=FirebaseDatabase.getInstance();
final DatabaseReference AllFacebase =database.getReference("всего").child("йй");
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt=findViewById(R.id.textView);
bubbleWrap=BubbleWrap.getInstance();
setupAddMoreButton();
setupPopActivityButton();
setupCocActivityButton();
txtintent=(TextView)findViewById(R.id.txtintent);
AllFacebase.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
bubul=String.valueOf(dataSnapshot.getValue());
txtintent.setText(bubul);
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
#Override
protected void onResume() {
super.onResume();
updateUI();
}
private void setupAddMoreButton(){
Button btn=findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
bubbleWrap.addMoreBubbles();
updateUI();
}
});
}
private void setupPopActivityButton(){
Button btn=findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
private void setupCocActivityButton(){
Button btn=findViewById(R.id.buttoncoc);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
private void updateUI(){
txtintent.setText(String.format(Locale.getDefault(),"%d",
bubbleWrap.getNumBubbles()));
}
}
second activity
activity, where I change the variable, I want to write to Firebase
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pop);
bubbleWrap=BubbleWrap.getInstance();
final TextView txt=findViewById(R.id.textView2);
setupPopButton();
updateUI();
Intent intent=new Intent();
intent.putExtra("bubles", bubbleWrap.getNumBubbles());
}
private void setupPopButton(){
Button btn=findViewById(R.id.cocbtb);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
bubbleWrap.popBubble();
updateUI();
}
});
}
private void updateUI(){
TextView txt=findViewById(R.id.textView2);
txt.setText(String.format(Locale.getDefault(),
"Bubbles left: %d",
bubbleWrap.getNumBubbles()));
}
}
Singleton
public class BubbleWrap {
private static final int ADD_MORE_BUBBLES = 10;
private int numBubbles;
private static BubbleWrap instance;
private BubbleWrap(){
}
public static BubbleWrap getInstance(){
if(instance==null){
instance=new BubbleWrap();
}
return instance;
}
public int getNumBubbles() {
return numBubbles;
}
public void addMoreBubbles(){
numBubbles+=ADD_MORE_BUBBLES;
}
public void popBubble() {
numBubbles--;
}
public void saveintent(){
}
}

Failed to convert value of type java.util.HashMap to String and app crashes

public class MainActivity extends AppCompatActivity {
//points to the root node of the database
DatabaseReference mRootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference mConditionRef = mRootRef.child("condition");
TextView content;
Button sunny, foggy;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
content = (TextView) findViewById(R.id.condition);
sunny = (Button) findViewById(R.id.sunny);
foggy = (Button) findViewById(R.id.foggy);
}
#Override
protected void onStart() {
super.onStart();
mConditionRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
String text = dataSnapshot.getValue(String.class);
content.setText(text);
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
sunny.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mConditionRef.setValue("Sunny");
mRootRef.child("condition").push().setValue("Abhijeet Jain2");
}
});
foggy.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mConditionRef.setValue("Foggy");
}
});
}
}
The string gets added in the realtime database with a automatic made id but the app crashes as soon as I press the button "sunny".
What could be the reason and the solution?

How to integrate facebook login in Backendless?

This is My LoginActivity.java
public class LoginActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener,
View.OnClickListener {
#BindView(R.id.login_facebook)
Button loginFacebookBtn;
#BindView(R.id.privacy_policy)
TextView privacyPolicy;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
Backendless.setUrl(AppConstant.SERVER_URL);
Backendless.initApp(this, AppConstant.APPLICATION_ID, AppConstant.API_KEY);
String userToken = UserTokenStorageFactory.instance().getStorage().get();
if (userToken != null && !userToken.equals("")) {
Backendless.UserService.isValidLogin(new DefaultCallback<Boolean>(this) {
#Override
public void handleResponse(Boolean isValidLogin) {
if (isValidLogin && Backendless.UserService.CurrentUser() == null) {
String currentUserId = Backendless.UserService.loggedInUser();
if (!currentUserId.equals("")) {
Backendless.UserService.findById(currentUserId, new DefaultCallback<BackendlessUser>(LoginActivity.this, "Logging in...") {
#Override
public void handleResponse(BackendlessUser currentUser) {
super.handleResponse(currentUser);
Backendless.UserService.setCurrentUser(currentUser);
ActivityHelper.start(LoginActivity.this, MainActivity.class);
finish();
}
});
}
}
super.handleResponse(isValidLogin);
}
});
}
loginWithFacebook();
privacyPolicy.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(LoginActivity.this, PrivacyPolicy.class));
}
});
registerDevice();
}
private void registerDevice() {
Backendless.Messaging.registerDevice(AppConstant.GCM_SENDER_ID, AppConstant.MESSAGING_CHANNEL, registerCallback());
}
private DefaultCallback<Void> registerCallback() {
return new DefaultCallback<Void>(this) {
#Override
public void handleResponse(Void response) {
super.handleResponse(response);
}
#Override
public void handleFault(BackendlessFault fault) {
super.handleFault(fault);
}
};
}
private void loginWithFacebook() {
loginFacebookBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onLoginWithFacebookButtonClicked();
}
});
}
private void onLoginWithFacebookButtonClicked() {
Map<String, String> facebookFieldsMapping = new HashMap<>();
facebookFieldsMapping.put("name", "name");
facebookFieldsMapping.put("email", "email");
List<String> facebookPermissions = new ArrayList<>();
facebookPermissions.add("email");
Backendless.UserService.loginWithFacebook(LoginActivity.this, null, facebookFieldsMapping, facebookPermissions, new SocialCallback<BackendlessUser>(LoginActivity.this) {
#Override
public void handleResponse(BackendlessUser response) {
ActivityHelper.start(LoginActivity.this, MainActivity.class);
finish();
}
#Override
public void handleFault(BackendlessFault fault) {
super.handleFault(fault);
Toasty.info(LoginActivity.this, "Try again, please ..", Toast.LENGTH_LONG).show();
}
}, true);
}
#Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
System.exit(0);
}
#Override
public void onClick(View view) {
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
}}
This is my facebook developers account settings
facebook screenshot 1
facebook screenshot 2
facebook screenshot 3
My Code is successfully running in android studio without any error.But when i run the application i am getting this error.
Can't load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.
error screenshot
I have created my LoginActivity.java bye taking this as a reference
https://backendless.com/documentation/users/android/index.html?users_facebook_login.htm
searched a lot in the web But Didn't get any relevant solution Can anybody help??
it looks like you are missing App Domain in your facebook settings (Settings > Basic > App Domains).
Try to add as your domain
api.backendless.com
If this is not working try to take a look at this https://backendless.com/documentation/manage/mgmt_social_settings.htm

How to fetch the department name for a particular User from Firebase in Android

My Database in firebase is in this format
I need that if a user login then for that particular UID I need his associated department name. So How to take the department name as a String.I use this code to fetch department name
String u_id=auth.getCurrentUser().getUid();
mdatabase=FirebaseDatabase.getInstance().getReference().child("Users").child(u_id).child("department");
user=mdatabase.getKey();
By this i don't get the result.Please provide solution
public class LoginPage extends AppCompatActivity {
private Button btnLogin;
private TextView ForgetText;
private EditText userText,PassText;
private String UserEmail,UserPassword;
private FirebaseAuth auth;
private FirebaseAuth.AuthStateListener mAuthlistener;
private ProgressBar progressBar;
private DatabaseReference mdatabase;
public String departmental;
//private Spinner dropdown;
Variables v=new Variables();
private String username,user;
private Intent i;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_page);
auth=FirebaseAuth.getInstance();
btnLogin=(Button)findViewById(R.id.btn_login);
ForgetText=(TextView)findViewById(R.id.textView3);
userText=(EditText)findViewById(R.id.email2);
PassText=(EditText)findViewById(R.id.password2);
progressBar=(ProgressBar)findViewById(R.id.progressBar2);
btnLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
SignIn();
}
});
ForgetText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(LoginPage.this,ForgotPassword.class));
}
});
}
public void SignIn(){
UserEmail=userText.getText().toString().trim();
UserPassword=PassText.getText().toString().trim();
if (UserEmail.isEmpty()){
Toast.makeText(LoginPage.this,"Please Enter the Email
Id",Toast.LENGTH_LONG).show();
}
else if (UserPassword.isEmpty())
{
Toast.makeText(LoginPage.this,"Please enter Valid
Password",Toast.LENGTH_LONG).show();
}
else {
auth.signInWithEmailAndPassword(UserEmail, UserPassword)
.addOnCompleteListener(LoginPage.this, new
OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
// If sign in fails, display a message to the user. If
sign in succeeds
// the auth state listener will be notified and logic
to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
// there was an error
Toast.makeText(LoginPage.this,"Error in
logging!!",Toast.LENGTH_LONG).show();
} else
{
if(FirebaseAuth.getInstance().getCurrentUser().getEmail().equals(v.admin))
startActivity(new
Intent(LoginPage.this,AdminUser.class));
else {
String u_id =
auth.getInstance().getCurrentUser().getUid();
mdatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(u_id).child("department");
ValueEventListener eventListener = new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
String department = (String) dataSnapshot.getValue();
}
#Override
public void onCancelled(DatabaseError databaseError) {}
};
mdatabase.addListenerForSingleValueEvent(eventListener);
Toast.makeText(LoginPage.this,u_id,Toast.LENGTH_LONG).show();
Toast.makeText(LoginPage.this,departmental,Toast.LENGTH_LONG).show();
/*i = new Intent(LoginPage.this, LoggedIn.class);
i.putExtra("hello_user",department);
startActivity(i);*/
}
Toast.makeText(LoginPage.this, "Logged In", Toast.LENGTH_LONG).show();
}
}
});
}
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
}
Please use this code:
String u_id = auth.getCurrentUser().getUid();
mdatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(u_id).child("department");
ValueEventListener eventListener = new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
String department = (String) dataSnapshot.getValue();
Log.d("TAG", department);
}
#Override
public void onCancelled(DatabaseError databaseError) {}
};
mdatabase.addListenerForSingleValueEvent(eventListener);
Hope it helps.

Categories

Resources