Chose Image From Gallery & Show in ImageView || Firebase Firestore A complete tutorial || PART 3 ||

Hey, what’s up guys welcome back to the 3rd part of the series in this series we will know how we can choose an Image from our gallery also we can snap an image from the camera and set that image in ImageView.

First thing first let’s add this dependency in your app level build file…

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
   

    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.google.firebase:firebase-firestore:11.8.0'
    implementation 'com.firebaseui:firebase-ui-firestore:3.2.2'

    implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
    implementation 'com.github.bumptech.glide:glide:4.6.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
    implementation'id.zelory:compressor:2.1.0'
}

Now create a new Activity under the Authentication folder and name it as StoreUserData.Now open activity_main.xml and add a new button Now start this new activity using this new button…I am not pasting the codes as you know how to do this or get the codes from GitHub link at the bottom.Now open the new activity XML file and paste this UI.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".authentication.StoreUserData">

    <ImageView
        android:id="@+id/user_image"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:clickable="true"
        android:focusable="true"
        android:scaleType="centerCrop"
        android:src="@mipmap/ic_launcher" />

    <EditText
        android:id="@+id/user_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="25dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="25dp"
        android:hint="Enter Your Name"
        android:inputType="textPersonName"
        android:textColor="#000"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/user_phone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="25dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="25dp"
        android:hint="Enter Your phone"
        android:inputType="phone"
        android:textColor="#000"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/user_address"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="25dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="25dp"
        android:hint="Enter Your Name"
        android:inputType="text"
        android:textColor="#000"
        android:textStyle="bold" />

    <Button
        android:id="@+id/submit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="30dp"
        android:layout_marginTop="25dp"
        android:layout_marginEnd="30dp"
        android:backgroundTint="#21a472"
        android:text="Submit"
        android:textAllCaps="false"
        android:textColor="#fff"
        android:textStyle="bold" />
</LinearLayout>

Now open the java file and call these UI elements using ID

public class StoreUserData extends AppCompatActivity {

    private ImageView userImage;
    private EditText userName, userPhone, userAddress;
    private Button submit;
   

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_store_user_data);

        userImage = findViewById(R.id.user_image);
        userName = findViewById(R.id.user_name);
        userPhone = findViewById(R.id.user_phone);
        userAddress = findViewById(R.id.user_address);
        submit = findViewById(R.id.submit);

      }
}

Now we need to choose the Image so when the user clicks on the ImageView we have to show chose option so set an on click listener to the ImageView and when the user clicks on that we do this…

public class StoreUserData extends AppCompatActivity {

    private ImageView userImage;
    private EditText userName, userPhone, userAddress;
    private Button submit;
    private ProgressDialog progressDialog;
    private Uri imageUri = null;
    private StorageReference storageReference;
    private FirebaseAuth firebaseAuth;
    private FirebaseFirestore firebaseFirestore;
    private String user_id;

    private Bitmap compressed;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_store_user_data);

        progressDialog = new ProgressDialog(this);

        userImage = findViewById(R.id.user_image);
        userName = findViewById(R.id.user_name);
        userPhone = findViewById(R.id.user_phone);
        userAddress = findViewById(R.id.user_address);
        submit = findViewById(R.id.submit);

        firebaseAuth = FirebaseAuth.getInstance();
        user_id = firebaseAuth.getCurrentUser().getUid();

        firebaseFirestore = FirebaseFirestore.getInstance();
        storageReference = FirebaseStorage.getInstance().getReference();

        userImage.setOnClickListener(new View.OnClickListener() {
                                         @Override
                                         public void onClick(View view) {
                                             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

                                                 if (ContextCompat.checkSelfPermission(StoreUserData.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

                                                     Toast.makeText(StoreUserData.this, "Permission Denied", Toast.LENGTH_LONG).show();
                                                     ActivityCompat.requestPermissions(StoreUserData.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);

                                                 } else {

                                                     choseImage();

                                                 }

                                             } else {

                                                 choseImage();

                                             }

                                         }

                                     }

        );

  }
  
  private void choseImage() {
        CropImage.activity()
                .setGuidelines(CropImageView.Guidelines.ON)
                .setAspectRatio(1, 1)
                .start(StoreUserData.this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            CropImage.ActivityResult result = CropImage.getActivityResult(data);
            if (resultCode == RESULT_OK) {

                imageUri = result.getUri();
                userImage.setImageURI(imageUri);


            } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {

                Exception error = result.getError();

            }
        }

    }
}

So we have done by choosing the Image nope we need to add one more thing So open your manifest file and add this two line of code under the Application tag… And add Two user Permission

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.monstertechno.firestoretutorial">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".authentication.LoginActivity" />
        <activity android:name=".authentication.SignupActivity" />
        <activity android:name=".authentication.StoreUserData"></activity>
        <activity
            android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
            android:theme="@style/Base.Theme.AppCompat" />
    </application>

</manifest>

That’s it now you can run this application and check It can now choose an image from your gallery and show that in an ImageView…


Thanks for your time… In the next part we will store this Image to Firebase Storage And show other details to firebase firestore.

Source code Available in GitHub- https://github.com/MonsterTechnoGit/Firebase-Firestore-A-complete-tutorial

You can get all the series Post using this link-> Click Here

Posts created 41

147 thoughts on “Chose Image From Gallery & Show in ImageView || Firebase Firestore A complete tutorial || PART 3 ||

  1. Hello there! This is kind of off topic but I need some advice from an established
    blog. Is it hard to set up your own blog? I’m not very techincal but I can figure things out pretty
    fast. I’m thinking about creating my own but I’m not sure where to start.
    Do you have any tips or suggestions? With thanks

  2. Heya! I realize this is somewhat off-topic however I needed to ask.
    Does building a well-established blog such as yours require a large amount of work?
    I am brand new to running a blog but I do write in my journal on a
    daily basis. I’d like to start a blog so I
    will be able to share my own experience and thoughts online.
    Please let me know if you have any ideas or tips for new aspiring bloggers.
    Thankyou!

  3. Hello there! I know this is kinda off topic but I’d figured
    I’d ask. Would you be interested in trading links or maybe guest
    writing a blog post or vice-versa? My site discusses a lot of
    the same subjects as yours and I believe we could greatly benefit from each other.

    If you happen to be interested feel free to send me an e-mail.
    I look forward to hearing from you! Superb blog by the way!

  4. I got this website from my buddy who shared with me on the topic of this web page and at the
    moment this time I am visiting this site and reading very informative content at this time.

  5. Great post. I used to be checking continuously this blog
    and I’m inspired! Very helpful info particularly the final section 🙂 I
    maintain such info much. I was seeking this certain information for a very lengthy time.

    Thank you and good luck.

  6. Great beat ! I would like to apprentice whilst you amend
    your website, how could i subscribe for a weblog website?
    The account aided me a acceptable deal. I were tiny bit acquainted of this your broadcast provided vivid transparent idea

  7. Heya i’m for the first time here. I found this board and I find It
    truly helpful & it helped me out much. I am hoping to give something again and
    aid others like you aided me.

  8. This is the perfect web site for everyone who wishes to
    understand this topic. You know a whole lot its
    almost hard to argue with you (not that I really will need to…HaHa).
    You definitely put a fresh spin on a subject which has been discussed for
    decades. Great stuff, just great!

  9. It is the best time to make some plans for the long run and it is time to be happy.

    I have read this publish and if I may I want to counsel you few attention-grabbing issues or advice.
    Maybe you could write next articles relating to this article.
    I desire to learn even more issues approximately
    it!

  10. Woah! I’m really enjoying the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s very difficult to get that “perfect balance” between user friendliness and visual appeal.
    I must say you have done a amazing job with this. In addition, the blog loads
    extremely quick for me on Safari. Exceptional Blog!

  11. Hey! This is my first visit to your blog!
    We are a group of volunteers and starting a new project in a community in the same niche.
    Your blog provided us beneficial information to work on. You have done a outstanding job!

  12. I like the valuable information you supply in your articles.

    I will bookmark your blog and test again right here frequently.
    I am rather sure I will learn lots of new stuff proper
    right here! Best of luck for the following!

  13. Simply desire to say your article is as amazing.
    The clarity to your publish is simply nice and i can suppose
    you’re a professional on this subject. Fine together with your permission allow me to take hold of your RSS feed to keep up to date with impending post.

    Thank you one million and please carry on the rewarding work.

  14. Very good blog! Do you have any tips for aspiring writers?
    I’m planning to start my own blog soon but I’m
    a little lost on everything. Would you advise starting with a free platform like WordPress or go for a paid
    option? There are so many options out there that I’m completely confused ..
    Any ideas? Bless you!

  15. Excellent post. I was checking continuously this blog and I
    am impressed! Very helpful info particularly the last part
    🙂 I care for such information much. I was seeking this particular info for a very long time.
    Thank you and best of luck.

  16. Definitely believe that which you said. Your favorite justification seemed to be on the
    web the simplest thing to be aware of. I say to you,
    I certainly get annoyed while people think about worries that they plainly don’t know about.
    You managed to hit the nail upon the top and defined
    out the whole thing without having side-effects , people can take a signal.
    Will likely be back to get more. Thanks

  17. Excellent post. Keep posting such kind of information on your blog.
    Im really impressed by your blog.
    Hi there, You have performed an excellent job. I’ll definitely
    digg it and in my opinion recommend to my friends.

    I am sure they’ll be benefited from this website.

  18. Its such as you read my thoughts! You seem to know so
    much about this, such as you wrote the guide in it
    or something. I believe that you just can do
    with some p.c. to power the message home a bit, however
    other than that, this is fantastic blog. A great read.
    I’ll certainly be back.

  19. Do you mind if I quote a couple of your posts as long
    as I provide credit and sources back to your site? My blog
    site is in the exact same area of interest as yours and
    my visitors would genuinely benefit from some of the information you present here.
    Please let me know if this ok with you. Appreciate it!

  20. I am extremely impressed with your writing skills and also with the layout on your blog.
    Is this a paid theme or did you modify it yourself? Either way keep up the excellent quality writing, it is rare to see a great blog like this one these days.

  21. I have been surfing online greater than three hours today, but I never found any attention-grabbing article like yours.

    It is beautiful worth enough for me. In my view, if all site owners and
    bloggers made good content material as you did, the web shall be much
    more helpful than ever before.

  22. I don’t even know how I ended up right here, however I assumed this
    post was great. I do not understand who you are however definitely you are going to a famous blogger when you aren’t already.
    Cheers!

  23. My spouse and I stumbled over here different web page and thought
    I may as well check things out. I like what I see so i am just following you.

    Look forward to finding out about your web page again.

  24. Hey There. I found your weblog using msn. This is an extremely neatly written article.
    I’ll be sure to bookmark it and come back to learn extra of your helpful information. Thanks for the post.
    I’ll definitely return.

  25. I have seen that car insurance organizations know the cars and trucks which are susceptible to accidents along with risks. Additionally , they know what form of cars are given to higher risk and also the higher risk they’ve got the higher the actual premium fee. Understanding the simple basics of car insurance will let you choose the right types of insurance policy that could take care of your family needs in case you get involved in any accident. Many thanks for sharing the particular ideas on the blog.

  26. I’m really enjoying the theme/design of your weblog.

    Do you ever run into any web browser compatibility
    issues? A number of my blog visitors have complained about my site not operating correctly in Explorer but looks
    great in Opera. Do you have any advice to help fix
    this issue? cheap flights 3gqLYTc

  27. Hello! I know this is kind of off topic but I was wondering
    if you knew where I could find a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having difficulty finding
    one? Thanks a lot! cheap flights 2CSYEon

  28. Spot on with this write-up, I absolutely believe this site needs a great deal more attention. I’ll probably be back again to
    see more, thanks for the information! 2CSYEon cheap flights

  29. I am really inspired along with your writing talents and also with the format on your weblog.

    Is this a paid subject matter or did you modify it yourself?
    Either way keep up the nice high quality writing, it’s uncommon to peer a great weblog
    like this one today.. cheap flights 32hvAj4

  30. It is appropriate time to make some plans for the future and it’s time to
    be happy. I’ve read this post and if I could I desire to suggest you some
    interesting things or advice. Perhaps you can write next articles referring to this article.
    I desire to read even more things about it! 3gqLYTc cheap flights

  31. My spouse and I absolutely love your blog and find
    almost all of your post’s to be precisely what I’m looking for.
    Do you offer guest writers to write content in your case?
    I wouldn’t mind writing a post or elaborating on many of the subjects you write with regards
    to here. Again, awesome web log!

  32. For example, pipes manufactured from PVC are inexpensive and they are frequently
    used in residential areas. If you are plahning to incorporate an addition to your residence, it
    will need excavating. Semi pedestal designs
    hold the similar selection of tops though the pedestal only protrudes below the simk far enough to pay the sink trasp
    and pipe work.

    My web blog … anchortext

  33. I am curious to find out what blog platform you are working
    with? I’m having some minor security issues with my latest blog and I’d like
    to find something more safeguarded. Do you have any recommendations?

  34. I like the valuable information you supply for your articles.
    I will bookmark your blog and take a look at again right here frequently.

    I am relatively certain I’ll be told lots of new stuff right right here!

    Good luck for the following!

  35. Hey! I know this is somewhat off topic but I was wondering if
    you knew where I could find a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having trouble finding one?
    Thanks a lot!

  36. My developer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the expenses.
    But he’s tryiong none the less. I’ve been using WordPress on numerous websites for
    about a year and am anxious about switching to another platform.
    I have heard very good things about blogengine.net.
    Is there a way I can import all my wordpress content into it?
    Any help would be really appreciated!

  37. Then, when yoou are ready get a new home, give you the
    skills offered through the LWYW program.
    As to consider available homes with your native Knoxville plus your siblings’ current dwellings in Farragut, it
    might be impossible to never see tthe benefits offered by Lanesborough Apartments and Derby Run Apartments, located inside aforementioned cities respectively.
    The professional you ire needs tto be conversant orr higher
    up to now with the latest accounting systems, particularly those systems
    specifically intended to make property management easier.

    Feell free to visit my website anchortext – Lynn,

  38. Whether you are decorating one room, all of your office or home, or are constructing
    a home yourself, you will want the very best flooring offered to make sure that your
    floors are beautiful and last test of time. A professional mold inspection team
    can come to your house to check our home’s air.
    It is well said “everything won’t show 100% results”, so bamboo material in addition has some disadvantages besides many important advantages.

    Feel free to visit my page … jam besi asli (Kristen)

  39. Most of the people gain their experience with IT organization and
    begin theiir own enterprise. Thesee investments coulod include certificate of deposits and certificate of investments
    in addition. You will just nedd to give you
    a short period of notice in your current landlord and finnd some other place to rent.

    Have a look at my webpage – anchortext (Ryan)

  40. I’m extremely inspired with your writing skills as
    neatly as with the format in your blog. Is that this
    a paid theme or did you customize it your self? Either way stay up the excellent high quality writing, it is uncommon to look
    a nice weblog like this one nowadays..

  41. I am really loving the theme/design of your site. Do you
    ever run into any web browser compatibility problems?
    A number of my blog audience have complained
    about my website not working correctly in Explorer
    but looks great in Safari. Do you have any suggestions to help fix this problem?

  42. Hi there this is kinda of off topic but I was wondering if
    blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding expertise so I
    wanted to get advice from someone with experience.

    Any help would be enormously appreciated!

  43. The aforementioned points are enough to convince one to opt for the
    web-bazaar. And when trying to find an oven, you will need to
    think about whether your kitchen area is suitd for any gas or electric stove.
    A bay window adds beauty andd architectural pazazz to
    yourr home style.

    My web page … kursi tamu sofa Jepara [Meredith]

  44. Undeniably believe that that you stated. Your favorite reason appeared to be at the internet the simplest thing to take note of.
    I say to you, I certainly get irked while other people think about
    issues that they plainly do not know about. You managed to hit
    the nail upon the highest and also defined out the entire thing without having
    side-effects , other people can take a signal. Will probably be
    again to get more. Thanks

  45. Perhaps essentially the most valuable lesson from this experience is never
    to adopt an unexplainedd condition like for granted.
    They are going to bite using the wooden with your houees structure, and ultimately it’ll just fall
    apart. If you aren’t sure how to start using this type
    of then the internet is usually a great place to get started
    on – however you just need to be sure you search in the right way.

    Also visit my website :: anchortext (Rhea)

  46. You decide which aspects are critical for your firearm safe to perform.
    This is why these cabinets can easily carry a great deal of load and in addition carry a quantity of files
    as well as other materials with ease. Not only that, there is also the chance exhibit your artistic power
    while enjoying your extra time and resources that could be devoted to other important matters once you’re carried
    out with refacing your home cabinet.

  47. Ꭺmazon Kindle will be tһe most recent fashion in online sales, and
    everyone’s ɗoing the work . Thus based upon the numbеr of replicates үou would like to
    cuгrently haᴠe, find the form ⲟf booҝ pгinters.
    You can certainly you could make your sheet fed printing busіness
    grow using the гight marketing and lastlу, hard work.

  48. You decide which aspects are critical for your firearm safe to perform.
    This is why these cabinets can easily carry a great deal of load and in addition carry a quantity of files
    as well as other materials with ease.blog post

  49. Sierra Software Ltd was founded in 2010 and is
    headquartered in Nottingham, UK to provide engineering
    service to many industries. Sierra Software GmbH was
    founded in 2018 and is headquartered in Austria.
    freertos

  50. Pretty section of content. I just stumbled upon your weblog and in accession capital to assert that I acquire in fact enjoyed account
    your blog posts. Anyway I’ll be subscribing to your augment and even I achievement you access consistently fast.

  51. Thanks for sharing excellent informations. Your web-site is so cool. I’m impressed by the details that you have on this site. It reveals how nicely you perceive this subject. Bookmarked this web page, will come back for more articles. You, my friend, ROCK! I found just the information I already searched all over the place and just couldn’t come across. What an ideal website.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top