create account

Save Profile Image | Android App Development | Lecture#61 | Hive Learners by faisalamin

View this thread on: hive.blogpeakd.comecency.com
· @faisalamin ·
$6.50
Save Profile Image | Android App Development | Lecture#61 | Hive Learners
<center><h2>๐“–๐“ป๐“ฎ๐“ฎ๐“ฝ๐“ฒ๐“ท๐“ฐ๐“ผ</h2></center>
<div class="text-justify">

Hi Hive Learners, I hope you all are well. In the previous lecture, we learn how to get the Image Uri and Upload it to Firebase Storage. There is another way to save the Profile Image during the Signup. We only need to add the Image Uri with the UsersData. It will auto-upload the image and save it in Firebase User Profile Data. I also missed some useful code to share in the last lecture. It helps us to get the correct Image Uri. I will share it today. Let's get started.

![](https://images.ecency.com/DQmXyX8MUk9rmv8yaxsZa7Q4V3m8jtDpZJFDsPbLGgrkyvi/multi_purpose_8_.png)

## [GitHub Link](https://github.com/faisalamin9696/HiveLearners2)

Use this GitHub project to clone into your directory. The following lecture will update it so you will never miss the latest code. Happy Coding!

## What Should I Learn

- Save the image Profile with UserData

## Assignment

- Save user Profile image

## Procedure

First, we need to get the correct Image Uri of the captured image using the camera. Here are some functions that help us to get the correct Image Uri. I found this solution from the [StackOverFlow](https://stackoverflow.com/). First, we get the tempUri of the selected file sometimes it does not work with firebase with the latest Android Versions. So we need to get use the getRealPathFromURI to get the correct patch of the File and we can parse this File to correct Uri.

```
 public Uri getImageUri(Context inContext, Bitmap inImage) {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
        String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
        return Uri.parse(path);
    }

    public String getRealPathFromURI(Uri uri) {
        String path = "";
        if (getContentResolver() != null) {
            Cursor cursor = getContentResolver().query(uri, null, null, null, null);
            if (cursor != null) {
                cursor.moveToFirst();
                int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
                path = cursor.getString(idx);
                cursor.close();
            }
        }
        return path;
    }
```

We need to set a Global variable profileImageUri and we will update it on the Activity result. 

![](https://images.ecency.com/DQmdMP37QFehyRk1ctps2s2JwMmkTThkdxyG5zJURp1UvUE/image.png)

Remove/Comment the upload image line from the ActivityRersult section and save the Uri to the variable.

![](https://images.ecency.com/DQmWGYYaNhLvBouW2Q5BJrx7wL3uuPqBk6sXSfRdVxLWBLg/image.png)

Now we need to use this profileImageUri in UserProfileChangeRequest.

```
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
                            .setDisplayName(username)
                            .setPhotoUri(profileImageUri)
                            .build();
```

![](https://images.ecency.com/DQmZ7a1hyjVHA6JMkZcbNB5JoFaApHnAK1TD82BkjTySSeW/image.png)

We also need to set the check before this.

![](https://images.ecency.com/DQmXdMqdXKdApLgddD3bkUw7JsU8LQYWTpUUTDUR4KbbQch/image.png)

We can set an image source in the XML file to show the Profile Image Icon.

![](https://images.ecency.com/DQmS1PY8FdjKstjJccqLYx2Yv9UeXC6yptXbUJu7MXa7eew/image.png)


All Done! Now when a user signup Firebase will store this selected profile image to UserProfile.</div>

<center>
![hl_divider.png](https://images.ecency.com/DQmabQycJhW8DT8a634z3wQaVXvPZ5KMii2LYbaWZ3PsaRy/hl_divider.png)

<h2>Thank You</h2>

![hl_footer_banner.png](https://images.ecency.com/DQmZ4HF3hjV4HwJXuw8vRJ6B6CiMC3kUkkoihjtm7z2Gii7/hl_footer_banner.png)
<div class="pull-left"><a href="https://discord.gg/7Bzqv4qUMT">
<img src="https://cdn.steemitimages.com/DQmXd6PwGUHRgSDkWtwKfDvdFpaLHXvXBdK7wnYZeqe1GUa/discord_animation_logo.gif"/></a>
</center>
๐Ÿ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 181 others
๐Ÿ‘Ž  
properties (23)
authorfaisalamin
permlinksave-profile-image-or-android
categoryhive-153850
json_metadata"{"links": ["https://github.com/faisalamin9696/HiveLearners2", "https://stackoverflow.com/", "https://discord.gg/7Bzqv4qUMT"], "image": ["https://images.ecency.com/DQmXyX8MUk9rmv8yaxsZa7Q4V3m8jtDpZJFDsPbLGgrkyvi/multi_purpose_8_.png", "https://images.ecency.com/DQmdMP37QFehyRk1ctps2s2JwMmkTThkdxyG5zJURp1UvUE/image.png", "https://images.ecency.com/DQmWGYYaNhLvBouW2Q5BJrx7wL3uuPqBk6sXSfRdVxLWBLg/image.png", "https://images.ecency.com/DQmZ7a1hyjVHA6JMkZcbNB5JoFaApHnAK1TD82BkjTySSeW/image.png", "https://images.ecency.com/DQmXdMqdXKdApLgddD3bkUw7JsU8LQYWTpUUTDUR4KbbQch/image.png", "https://images.ecency.com/DQmS1PY8FdjKstjJccqLYx2Yv9UeXC6yptXbUJu7MXa7eew/image.png", "https://images.ecency.com/DQmabQycJhW8DT8a634z3wQaVXvPZ5KMii2LYbaWZ3PsaRy/hl_divider.png", "https://images.ecency.com/DQmZ4HF3hjV4HwJXuw8vRJ6B6CiMC3kUkkoihjtm7z2Gii7/hl_footer_banner.png", "https://cdn.steemitimages.com/DQmXd6PwGUHRgSDkWtwKfDvdFpaLHXvXBdK7wnYZeqe1GUa/discord_animation_logo.gif"], "thumbnails": ["https://images.ecency.com/DQmXyX8MUk9rmv8yaxsZa7Q4V3m8jtDpZJFDsPbLGgrkyvi/multi_purpose_8_.png", "https://images.ecency.com/DQmdMP37QFehyRk1ctps2s2JwMmkTThkdxyG5zJURp1UvUE/image.png", "https://images.ecency.com/DQmWGYYaNhLvBouW2Q5BJrx7wL3uuPqBk6sXSfRdVxLWBLg/image.png", "https://images.ecency.com/DQmZ7a1hyjVHA6JMkZcbNB5JoFaApHnAK1TD82BkjTySSeW/image.png", "https://images.ecency.com/DQmXdMqdXKdApLgddD3bkUw7JsU8LQYWTpUUTDUR4KbbQch/image.png", "https://images.ecency.com/DQmS1PY8FdjKstjJccqLYx2Yv9UeXC6yptXbUJu7MXa7eew/image.png", "https://images.ecency.com/DQmabQycJhW8DT8a634z3wQaVXvPZ5KMii2LYbaWZ3PsaRy/hl_divider.png", "https://images.ecency.com/DQmZ4HF3hjV4HwJXuw8vRJ6B6CiMC3kUkkoihjtm7z2Gii7/hl_footer_banner.png", "https://cdn.steemitimages.com/DQmXd6PwGUHRgSDkWtwKfDvdFpaLHXvXBdK7wnYZeqe1GUa/discord_animation_logo.gif"], "tags": ["hive-153850", "stem", "diy", "pakistan", "education", "android", "firebase", "programming", "java"], "description": "", "app": "ecency/3.0.26-vision", "format": "markdown+html"}"
created2022-08-31 16:00:39
last_update2022-08-31 16:00:39
depth0
children10
last_payout2022-09-07 16:00:39
cashout_time1969-12-31 23:59:59
total_payout_value3.275 HBD
curator_payout_value3.226 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,936
author_reputation104,701,778,605,493
root_title"Save Profile Image | Android App Development | Lecture#61 | Hive Learners"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id116,200,655
net_rshares9,354,966,218,979
author_curate_reward""
vote details (246)
@azircon ·
These posts have little to no engagement. Without that, I will say they are a farming operation. 

Who is reading and finding any benefits from this?
๐Ÿ‘Ž  ,
properties (23)
authorazircon
permlinkre-faisalamin-rhsbx6
categoryhive-153850
json_metadata{"tags":["hive-153850"],"app":"peakd/2022.07.1"}
created2022-09-06 11:00:42
last_update2022-09-06 11:00:42
depth1
children8
last_payout2022-09-13 11:00:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length149
author_reputation817,926,257,032,838
root_title"Save Profile Image | Android App Development | Lecture#61 | Hive Learners"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id116,363,956
net_rshares-8,820,953,394
author_curate_reward""
vote details (2)
@faisalamin ·
Even no one reading the post. But It's a series if someone need any help at any stage they can get it on Hive. How can you say it is a farming operation.
๐Ÿ‘Ž  
properties (23)
authorfaisalamin
permlinkre-azircon-202296t16209196z
categoryhive-153850
json_metadata{"tags":["hive-153850"],"app":"ecency/3.0.26-vision","format":"markdown+html"}
created2022-09-06 11:20:09
last_update2022-09-06 11:20:09
depth2
children7
last_payout2022-09-13 11:20:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length153
author_reputation104,701,778,605,493
root_title"Save Profile Image | Android App Development | Lecture#61 | Hive Learners"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id116,364,318
net_rshares-6,984,453,655
author_curate_reward""
vote details (1)
@azircon · (edited)
Dude, I will made it plain for you. If I see 100% โ€œself-voteโ€ on your account I will adjust it.

No if but or coconut.

Alright?
๐Ÿ‘Ž  ,
properties (23)
authorazircon
permlinkre-faisalamin-rhsd0x
categoryhive-153850
json_metadata{"tags":"hive-153850"}
created2022-09-06 11:24:33
last_update2022-09-06 11:25:00
depth3
children6
last_payout2022-09-13 11:24:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length128
author_reputation817,926,257,032,838
root_title"Save Profile Image | Android App Development | Lecture#61 | Hive Learners"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id116,364,398
net_rshares-8,845,375,553
author_curate_reward""
vote details (2)
@stemsocial ·
re-faisalamin-save-profile-image-or-android-20220831t195924200z
<div class='text-justify'> <div class='pull-left'>
 <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div>

Thanks for your contribution to the <a href='/trending/hive-196387'>STEMsocial community</a>. Feel free to join us on <a href='https://discord.gg/9c7pKVD'>discord</a> to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.&nbsp;<br />&nbsp;<br />
</div>
properties (22)
authorstemsocial
permlinkre-faisalamin-save-profile-image-or-android-20220831t195924200z
categoryhive-153850
json_metadata{"app":"STEMsocial"}
created2022-08-31 19:59:24
last_update2022-08-31 19:59:24
depth1
children0
last_payout2022-09-07 19:59:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length565
author_reputation22,928,294,988,376
root_title"Save Profile Image | Android App Development | Lecture#61 | Hive Learners"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id116,206,107
net_rshares0