Let us suppose you are developing an Android App that pulls images from a SharePoint list and displays in your mobile app, either as a Power BI report or other forms of image content. Have you ever tried that? You might face broken links, distorted image and other issues.
Display SharePoint images on Android
In this article, I will walkthrough step by step with code on how to display images from SharePoint list perfectly on Android without any issues.
Create a New Project in your Android Studio.
Open your AndroidManifest.xml file and add the below permissions.
<uses-permission android_name=”android.permission.INTERNET” />
Open your Project and goto the App Level gradle file (this file is shown below the app.iml file)
Paste the Glide library URL in your dependencies file inside the gradle file.
The file 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 .Code is below
ImageView mImgNews = (ImageView) findViewById(R.id.img_news);
Get image URL from SharePoint list page using REST API. Eg URL below
String ImageUrl = "Your tenent name"+"/Project%20Documents/HF-004/Task-9/Jai.jpg";
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, and also pass an image URL.
The code is shown below:
GlideUrl glideUrl = new GlideUrl(ImageUrl, new LazyHeaders.Builder().addHeader(“Cookie”, “rtFa=” + Your Rdfa + “;
FedAuth=” + your FedAuth).build());
Finally load your glideUrl and display an image. Code is shown below
That’s all and now you have displayed SharePoint image on your Android without any distortions or broken links whatsoever. To make your life easy, I have packaged the code which you can download and reuse it just by making few modifications to the code like the URL value we have passed etc. You can download the code from here.
If you still face any issues or need my assistance, I am always available in the comments section below.