Android apps
Live Connect provides an API for the Google Android mobile technology platform. The Android API enables your apps running on Froyo, Gingerbread, Honeycomb, and Ice Cream Sandwich versions of Android to work with info in Outlook.com, Microsoft OneDrive, and other services that are compatible with Live Connect. Although you can still write code to call the Live Connect Representational State Transfer (REST) API directly, the Android API now makes your coding tasks easier.
Before you can start calling the Live Connect APIs, you need a client ID. For instructions, see Configuring your app.
Prerequisites
You can use the Live Connect Android API to target Android platform versions 2.2 and later. Note that the Live Connect Android API requires use of the platform API level corresponding to the platform version that you're targeting, as shown here.
| Platform name | Version | API level |
|---|---|---|
|
Jelly Bean |
4.1 |
16 |
|
Ice Cream Sandwich |
4.0 |
14 |
|
Honeycomb |
3.2 |
13 |
|
Honeycomb |
3.1 |
12 |
|
Honeycomb |
3.0 |
11 |
|
Gingerbread |
2.3.4 |
10 |
|
Gingerbread |
2.3.3 |
9 |
|
Froyo |
2.2 |
8 |
For info about the correct versions to use for the Java SE Development Kit (JDK), the Android software development kit (SDK), the Eclipse integrated development environment (IDE), and the Android Development Tools (ADT) plugin for Eclipse if you choose to use them, see the Android Developers website.
Referencing the Android API with Java
Before you can reference the Live Connect Android API in an Eclipse Android project, you must download the Live SDK for Android and compile the Live Connect Android API source code. Here's how.
To download the Live SDK for Android and compile the Live Connect Android API source code
-
Go to the website location where the Live SDK for Android is stored and download the SDK.
Note If you download the Live SDK for Android as a zip file, you must extract the contents of the zip file before you follow the steps in the next section.
You must now compile the downloaded Android API source code.
To compile the Android API source code
You need to compile the Android API source code only once. After you compile it on your computer, you can reference it from multiple Eclipse Android projects on that same computer.
- Start Eclipse, if it's not already running.
- Click File > Import.
- Expand General, click Existing Projects into Workspace, and then click Next.
- With the Select root directory option selected, click Browse.
- Go to and select the src folder within the downloaded Live SDK for Android, and then click OK.
- In the Projects box, select the LiveSdk check box.
- With the Copy projects into workspace check box selected, click Finish. Eclipse adds the LiveSdk project to the Package Explorer pane and then compiles the Android API source code in the background.
You can now reference the compiled Android API source code from your Eclipse Android projects.
To reference the compiled Android API source code in an Eclipse Android project
- In Eclipse, display the Package Explorer pane, if it's not already visible.
- Right-click your project's name, and then click Properties.
- In the list of project properties, click Android.
- In the Library area, click Add.
- Click LiveSdk and then click OK.
- Click OK. Eclipse sets a reference to the compiled Android API source code project, and you can now call the Live Connect Android API from your own Android project.
- With your project open, in the Package Explorer pane, open the AndroidManifest.xml file.
- In the editor, click the Permissions tab.
- Click Add.
- Click Uses Permission and then click OK.
- In the Name list, click android.permission.INTERNET.
- Save the AndroidManifest.xml file.
Code sample
To get you started, here's the basic code that shows how to reference the Android API, invite a user to sign in, and get the signed-in user's permission to get his or her basic profile info.
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/resultTextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Results will display here." /> </LinearLayout>
JavaCodeSample.java
package com.live.dev; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import java.util.Arrays; import com.microsoft.live.LiveAuthException; import com.microsoft.live.LiveAuthListener; import com.microsoft.live.LiveAuthClient; import com.microsoft.live.LiveConnectSession; import com.microsoft.live.LiveConnectClient; import com.microsoft.live.LiveStatus; public class JavaCodeSample extends Activity implements LiveAuthListener { private LiveAuthClient auth; private LiveConnectClient client; private TextView resultTextView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.resultTextView = (TextView)findViewById(R.id.resultTextView); this.auth = new LiveAuthClient(this, MyConstants.APP_CLIENT_ID); } @Override protected void onStart() { super.onStart(); Iterable<String> scopes = Arrays.asList("wl.signin", "wl.basic"); this.auth.login(scopes, this); } public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) { if(status == LiveStatus.CONNECTED) { this.resultTextView.setText("Signed in."); client = new LiveConnectClient(session); } else { this.resultTextView.setText("Not signed in."); client = null; } } public void onAuthError(LiveAuthException exception, Object userState) { this.resultTextView.setText("Error signing in: " + exception.getMessage()); client = null; } }
MyConstants.java (where MY CLIENT ID is your app's client ID—for example, 00000000603E7410)
package com.live.dev; final class MyConstants { static final String APP_CLIENT_ID = "MY CLIENT ID"; }
Next steps
From here, we suggest that you continue your learning with the info in Core concepts, Identity API, Outlook.com API, and OneDrive API.