Written by

Hari Murugesan

Share

  

Category

see all categories

How to display Office 365 Profile Image in Android

In this article, let us go through how to display Office 365 profile image in your Android app. If you have plans for an Android app related to Office 365 or SharePoint, you might need to get your O365 profile image in your app. This blogpost walks you through the complete process step by step.

Open Android studio.

Go to File and Create a New Project.

This would create a new project. You can open a manifest file and provide Internet connection. If there is no Internet connection, it will not open the profile connection. Below is the code for Internet Connection.

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

Open your Project and goto the App Level gradle file (this file is displayed below the app.iml file)

Paste the Glide library URL in your dependencies file inside the gradle file.

The code is below

                 dependencies {
                          compile 'com.github.bumptech.glide:glide:3.7.0'

                   }

Now, open your XML file inside the resource/layout.

Create an Image View and add image ID in that file.  The code is for the same is below

    <ImageView
   
android:layout_width="120dp"
   
android:layout_height="120dp"
   
android:layout_gravity="center"
   
/>

Open your class file and read your image view. The Code for the same is given below

                 ImageView mImgNews = (ImageView)findViewById(R.id.img_profile);

Now you get your profile details using rest api call. The api url is below

                 “Your tenenat name” + “/api/web/currentUser”.

 

Now you got the Current UserDetails and in the details to get a email id.

Declare GlideUrl and create an object in your class file.

In that object, you are required to pass a header value like Rdfa and FedAuth.  (Get Rdfa fedauth link http://blog.hubfly.com/mobile/login-SharePoint-on-your-android-app)  and also pass an image URL.

Now you need to format the image url like below.

  ImageUrl = “TenantUrl”

/sites/dev/_layouts/15/userphoto.aspx?size=L&accountname=”EmailId”

Now you show the image using glide library. The code is below

GlideUrl glideUrl = new GlideUrl(ImageUrl, new

LazyHeaders.Builder().addHeader("Cookie", "rtFa=" + RTFA + ";

FedAuth=" + FedAuth).build());

Finally load your glideUrl and display the image. Code is shown below

 Glide.with(context).load(glideUrl)

        .placeholder(drawable)

        .error(drawable)

        .fitCenter()

        .diskCacheStrategy(DiskCacheStrategy.SOURCE)

        .thumbnail(0.5f)

        .crossFade()

        .into(view);

Now the profile image is displayed. Mission accomplished. Please do try and if you are struck somewhere, feel free to let me know via the comments below. I would be more than happy to answer you.

 
Hari Murugesan

Written by Hari Murugesan

Everybody gets crazy with iPhone release dates, but not Hari. He is so obsessed with Android and obviously, the perfect person to handle our Android apps development. When he plugs his earphone on and clicks opens Android Studio, we can trust he started shaping the App he is on. A gym bunny who spends the rest of the time shaping him as well.