Written by

Hari Murugesan

Share

  

Category

see all categories
intranet as a service

How to display images from SharePoint on your Android

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

                 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:id="@+id/img_news"
   
android:layout_width="90dp"
   
android:layout_height="70dp"
   
android:scaleType="fitXY"
   
android:src="@drawable/ic_user_profile"
   
android:visibility="visible" />

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.  (Get Rdfa fedauth link http://blog.hubfly.com/mobile/login-SharePoint-on-your-android-app)  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

Glide.with(context).load(glideUrl)
       .placeholder(drawable)
        .error(drawable)
        .fitCenter()
        .diskCacheStrategy(DiskCacheStrategy.SOURCE)
        .thumbnail(0.5f)
        .crossFade()
        .into(view);

misconceptions.png

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.

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.