Login and sign up issue - firebase

I am currently trying to build a new app (complete Novice) I have run into a strange issue on the login page.The sign up process works fine connects to firebase and returns to the login screen, then allows you to login and goes to the next activity. The problem occurs when you reload the app and use the details to re-login the login button does not work until you go into the sign up activity and come out of it then the login button works fine and allows you to sign in.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Button button = findViewById(R.id.signupbtn);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
openSignupActivity();
}
});
}
private void openSignupActivity() {
Intent intent = new Intent(LoginActivity.this, SignupActivity.class);
startActivity(intent);
setContentView(R.layout.activity_login);
LoginEmail = findViewById(R.id.LoginEmail);
LoginPassword = findViewById(R.id.LoginPassword);
Loginprogressbar = findViewById(R.id.Loginprogressbar);
mAuth = FirebaseAuth.getInstance();
findViewById(R.id.Loginbtn).setOnClickListener(this);
if conditions between
if(task.isSuccessful()){
Toast.makeText(getApplicationContext(),"Login Successful",Toast.LENGTH_SHORT).show();
finish();
startActivity(new Intent(LoginActivity.this,MainActivity.class));
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.Loginbtn:
Loginuser();
break;`enter code here`

Related

How can I go about uploading and receiving a users profile picture?

So far in my social media app, the user's data such as first name, last name, email, gender, and more can be saved in a firebase database and retrieved when needed. As of today, I got a working profile picture when first creating a profile you can tap on the empty profile picture icon and it loads up your gallery replacing it with whatever image the user chooses.
Although this is quite neat I need to be able to upload this image somehow under the Users node in my firebase database. I am quite lost when it comes to converting the bitmap data and after reading through some documentation it still confuses me. Below is my code for using a locally saved photo replacing it as the profile picture to show what I have so far.
#Override
public void onClick(View view)
{
if (view == profilePicture)
{
//Toast.makeText(this, "We made it to the onClick for image!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 0);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
Uri targetUri = data.getData();
Bitmap bitmap;
try
{
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri));
profilePicture.setImageBitmap(bitmap);
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The onClick method runs after the user taps the profile icon. Now I will show you the database I am currently working with, this is the Firebase real-time database, not the Firebase storage. While firebase storage might be more appropriate I can't seem to figure out how to tell whos photo would be who as it does not upload them with a user id associated with them.
Database Picture Here
Instead of uploading a bitMap, a far better solution for a simple problem like yours would be Firebase Storage, similar to the Database but you can upload files such as images with much ease.
Here are the methods I currently use in my app:
private void chooseImage() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
private void uploadImage() {
if(filePath != null)
{
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Uploading...");
progressDialog.show();
StorageReference ref = storageReference.child("images/"+userID);
ref.putFile(filePath)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressDialog.dismiss();
toastMessage("Uploaded");
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
progressDialog.dismiss();
toastMessage("Failed"+e.getMessage());
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
#Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0*taskSnapshot.getBytesTransferred()/taskSnapshot
.getTotalByteCount());
progressDialog.setMessage("Uploaded "+(int)progress+"%");
}
});
}
}

Can't get image from native gallery

I've created a test app to understand how to call the native gallery, select an image and display it on an imageView.
1st test
I had a simple setup. One activity and a fragment(residing within that activity) that has a button(calls gallery intent) and an imageView for the selected image. This worked perfectly.
2nd test
Changed the setup a bit by adding another activity and a tab host to the main activity. This new empty activity would be the launching activity and it's only purpose was to switch to the main activity that holds the fragment that calls the gallery intent. Everything works fine until I select the image from the gallery. Once the image is selected, it doesn't go back to the my test app. It's like a weird soft crash. Logcat doesn't display any errors so it's a bit hard to troubleshoot. I also placed a breakpoint on each line of the OnActivityResult override but they never hit.
I was hoping somebody would shed light on this matter.
SDK version is 23 and build tools is 23.0.3
Heres what I got so far:
Main2Activity(Launching activity)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
ActivityConfig.CreateActivity(MainActivity.class, this, true);
}
In case you were wondering what CreateActivity does:
public static void CreateActivity(Class activityClass, Context context,
boolean finishPreviousActivity)
{
Intent intent = new Intent(context, activityClass);
if (finishPreviousActivity)
{
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
}
context.startActivity(intent);
}
MainActivity(I only use the third position on the tabhost. That's where the fragment is)
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
tabHost.setup();
tabHost.addTab(Tabs.CreateTab("T1", R.id.tabFrag2, tabHost));
tabHost.addTab(Tabs.CreateTab("T2", R.id.tabFrag3, tabHost));
tabHost.addTab(Tabs.CreateTab("T3", R.id.tabFrag, tabHost));
tabHost.setCurrentTab(2);
}
Fragment
private ImageView imageView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_blank, container, false);
Button button = (Button)view.findViewById(R.id.Btn);
imageView = (ImageView)view.findViewById(R.id.Img);
button.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(intent, 100);
}
});
return view;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100)
imageView.setImageURI(data.getData());
}
After much trail an error I noticed that after selecting an image it was going back to the launching activity, but not through onCreate or it's overridden onActivityResult. It was going through onResult. My conclusion was redesign the whole interface in a way that only one activity was required

Xamarin Navigation.PopAsync can't work.I write the code like official example

The app.cs:
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new App9.LoginPage());
}
The LoginPage.cs
public LoginPage()
{
InitializeComponent();
}
async void OnLoginButtonClicked(object sender, EventArgs e)
{
Navigation.InsertPageBefore(new Page1(), this);
await Navigation.PopAsync();
}
I write this like official example,but when I click the login button,the LoginPage can't remove.And when I click the login button another time,it throw a exception.
In the official example ,the code work well.
How can I do to make this work?

Change user with Firebase Google user authentication

When using Firebase Google user authentication the user is immediately logged in if they have already authorized the application and only logged in to one Google account.
Is there a way to force the "Choose an account" dialog to appear so that the user has the opportunity to login to a different Google account or create a new one?
Currency as far as I know the user has to manually logout of the current Google account (or login to > 1) from Google.com to make the dialog appear.
You can force to choose an account with 'prompt' provider parameter.
var googleAuthProvider = new firebase.auth.GoogleAuthProvider();
googleAuthProvider.setCustomParameters({
prompt: 'select_account'
});
firebase.auth().signInWithRedirect(googleAuthProvider)
Tested with Firebase JavaScript SDK v4.1.2
You should sign out from Google explicitly:
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(status -> {
mFirebaseAuth.signOut();
});
Found the solution here
I'm trying to figure out the same thing. According to some Google documentation, it appears that you can force the account chooser with a "prompt" command (of "none", "select_account" or "consent"):
Force google account chooser
...however there appears to be no way to set the "prompt" value in any of Firebase's authentication methods (specifically authWithOAuthRedirect and authWithOAuthPopup).
Were you ever able to figure it out?
In my following code, the gooogle sign-in button every time prompts for choosing account...
public class MainActivity extends AppCompatActivity {
Button btn_signOut;
private GoogleSignInClient mGoogleSignInClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_signOut = findViewById(R.id.btnSignOut);
btn_signOut.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
signOut();
}
});
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}
private void signOut() {
mGoogleSignInClient.signOut()
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
finish();
}
});
}
}
Use this way to signout.
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(new
ResultCallback<Status>()
{
#Override
public void onResult(#NonNull Status status)
{
mAuth.signOut();
}
});
In flutter, use: GoogleSignIn().signOut();
(assumming you used the google_sign_in package)

NotificationCompat.Builder not working in Gingerbread

I'm attempting to use the NotificationCompat.Builder class in my app. The following code runs perfectly fine on an ICS phone, but not Gingerbread. From my understanding, doesn't the support library allow access to the Builder from phones as low as API level 4? Am I doing something fundamentally wrong?
public class MainActivity extends Activity implements OnClickListener {
NotificationCompat.Builder builder;
NotificationManager nm;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
builder = new NotificationCompat.Builder(this);
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
builder.setContentTitle("Test Notification")
.setContentText("This is just a test notification")
.setTicker("you have been notified")
.setSmallIcon(R.drawable.ic_stat_example)
.setWhen(System.currentTimeMillis());
findViewById(R.id.btn_notify).setOnClickListener(this);
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(arg0.getId() == R.id.btn_notify){
nm.notify(1, builder.build());
}
}
}
You have to supply the Intent which will be triggered when the notification is clicked. Otherwise, the notification will not be displayed on Gingerbread.
If you do not want to start the Activity when the notification is clicked, you can just pass an empty Intent as following.
Intent intent = new Intent();
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
builder.setContentTitle("Test Notification")
.setContentText("This is just a test notification")
.setTicker("you have been notified")
.setSmallIcon(R.drawable.ic_stat_example)
.setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent); // add this

Resources