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
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
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” +
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
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.