Reputation: 1
Currently, I'm building an application. In this application I want the user to choose and upload the profile image into the database. After uploading, the user should be able to view his profile image into the imageView given in the 'my profile' page. I've completed the task of choosing and uploading the image but the user. The main problem is I'm not able to figure out how the image should be shown into the imageView of the 'my profile'.
Here is the code for 'my profile' page:
//the code starts here
public class myprofile extends Signin implements View.OnClickListener {
TextView u_name, u_usn, u_year, u_branch, u_email;
ImageView imageView;
private Uri filePath;
private final int PICK_IMAGE_REQUEST = 71;
private FirebaseAuth firebaseAuth;
DatabaseReference databaseStudents;
private static final String TAG = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getOverflowMenu();
setContentView(R.layout.activity_myprofile);
u_name = (TextView) findViewById(R.id.name_myprofile);
u_usn = (TextView) findViewById(R.id.usn_myprofile);
u_year = (TextView) findViewById(R.id.year_myprofile);
u_branch = (TextView) findViewById(R.id.branch_myprofile);
u_email = (TextView) findViewById(R.id.email_myprofile);
imageView = (ImageView) findViewById(R.id.imageView);
//img fetch
firebaseAuth = FirebaseAuth.getInstance();
final FirebaseUser currentUser = firebaseAuth.getCurrentUser();
databaseStudents = FirebaseDatabase.getInstance().getReference("students");
databaseStudents.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
if (currentUser.getEmail().equalsIgnoreCase(ds.getValue(user.class).getEmail())) {
user userInfo = ds.getValue(user.class);
u_name.setText(userInfo.name);
u_usn.setText(userInfo.usn);
u_year.setText(userInfo.year);
u_email.setText(userInfo.email);
u_branch.setText(userInfo.branch);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
netConnection checkCon = new netConnection(this);
if (checkCon.isConnected() == false) {
new AlertDialog.Builder(this)
.setTitle("WARNING")
.setMessage("No Internet Connection!!\n\nEnable it..!!!")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(Settings.ACTION_SETTINGS);
startActivity(intent);
}
})
.show();
}
}
private void getOverflowMenu() {
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Upvotes: 0
Views: 43
Reputation: 236
You can use the Glide library for image loading from anywhere.
First You want to add Glide Dependancy from the Documentation attached HERE
The Dependancy is: implementation 'com.github.bumptech.glide:glide:4.7.1'
dependencies {
implementation 'com.github.bumptech.glide:glide:4.7.1'
}
add above lines in build.gradle(Module:app) app level file
and then update the below code in the java file
ImageView imageView = (ImageView) findViewById(R.id.imageView);
for (DataSnapshot ds : dataSnapshot.getChildren()) {
if (currentUser.getEmail().equalsIgnoreCase(ds.getValue(user.class).getEmail())) {
user userInfo = ds.getValue(user.class);
u_name.setText(userInfo.name);
u_usn.setText(userInfo.usn);
u_year.setText(userInfo.year);
u_email.setText(userInfo.email);
u_branch.setText(userInfo.branch);
Glide.with(context)
.asBitmap()
.load(userInfo.imageVariableName)
.into(imageView);
}
}
Upvotes: 1