title | description | services | documentationcenter | author | manager | editor | ms.assetid | ms.service | ms.devlang | ms.topic | ms.tgt_pltfrm | ms.workload | ms.date | ms.author | ms.custom |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
include file |
include file |
active-directory |
dev-center-name |
andretms |
mtillman |
820acdb7-d316-4c3b-8de9-79df48ba3b06 |
active-directory |
na |
include |
na |
identity |
09/13/2018 |
andret |
include file |
Do you want to download this sample's Android Studio project instead? Download a project, and skip to the Configuration step to configure the code sample before you execute it.
- Open Android Studio, and then select File > New > New Project.
- Name your application, and then select Next.
- Select API 21 or newer (Android 5.0), and then select Next.
- Leave Empty Activity as it is, select Next, and then select Finish.
-
In Android Studio, select Gradle Scripts > build.gradle (Module: app).
-
Under Dependencies, paste the following code:
compile ('com.microsoft.identity.client:msal:0.1.+') { exclude group: 'com.android.support', module: 'appcompat-v7' } compile 'com.android.volley:volley:1.0.0'
The package in the preceding code installs Microsoft Authentication Library. MSAL handles all token operations including acquiring, caching, refreshing, and deleting. The tokens are needed to access the APIs protected by Microsoft's identity platform.
-
Go to res > layout, and then open activity_main.xml.
-
Change the activity layout from
android.support.constraint.ConstraintLayout
or other toLinearLayout
. -
Add the
android:orientation="vertical"
property to theLinearLayout
node. -
Paste the following code into the
LinearLayout
node, replacing the current content:<TextView android:text="Welcome, " android:textColor="#3f3f3f" android:textSize="50px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="15dp" android:id="@+id/welcome" android:visibility="invisible"/> <Button android:id="@+id/callGraph" android:text="Call Microsoft Graph" android:textColor="#FFFFFF" android:background="#00a1f1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="200dp" android:textAllCaps="false" /> <TextView android:text="Getting Graph Data..." android:textColor="#3f3f3f" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:id="@+id/graphData" android:visibility="invisible"/> <LinearLayout android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1" android:gravity="center|bottom" android:orientation="vertical" > <Button android:text="Sign Out" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="15dp" android:textColor="#FFFFFF" android:background="#00a1f1" android:textAllCaps="false" android:id="@+id/clearCache" android:visibility="invisible" /> </LinearLayout>