Add apps to android sdk

SDK Manager

The Android SDK separates tools, platforms, and other components into packages you can download using the SDK Manager. For example, when the SDK Tools are updated or a new version of the Android platform is released, you can use the SDK Manager to quickly download them to your environment.

You can launch the SDK Manager in one of the following ways:

  • From Eclipse (with ADT), select Window >Android SDK Manager.
  • From Android Studio, select Tools >Android >SDK Manager.
  • On Windows, double-click the SDK Manager.exe file at the root of the Android SDK directory.
  • On Mac or Linux, open a terminal and navigate to the tools/ directory in the location where the Android SDK is installed, then execute android sdk .

You can select which packages you want to download by toggling the checkboxes on the left, then click Install to install the selected packages.

Figure 1. The Android SDK Manager shows the SDK packages that are available, already installed, or for which an update is available.

There are several different packages available for the Android SDK. The table below describes most of the available packages and where they’re located in your SDK directory once you download them.

Here’s an outline of the packages required and those we recommend you use:

SDK Tools Required. Your new SDK installation already has the latest version. Make sure you keep this up to date. SDK Platform-tools Required. You must install this package when you install the SDK for the first time. SDK Platform Required.You must download at least one platform into your environment so you’re able to compile your application. In order to provide the best user experience on the latest devices, we recommend that you use the latest platform version as your build target. You’ll still be able to run your app on older versions, but you must build against the latest version in order to use new features when running on devices with the latest version of Android.

To get started, download the latest Android version, plus the lowest version you plan to support (we recommend Android 2.2 for your lowest version).

System Image Recommended. Although you might have one or more Android-powered devices on which to test your app, it’s unlikely you have a device for every version of Android your app supports. It’s a good practice to download system images for all versions of Android your app supports and test your app running on them with the Android emulator. Android Support Recommended. Includes a static library that allows you to use some of the latest Android APIs (such as fragments, plus others not included in the framework at all) on devices running a platform version as old as Android 1.6. All of the activity templates available when creating a new project with the ADT Plugin require this. For more information, read Support Library. SDK Samples Recommended. The samples give you source code that you can use to learn about Android, load as a project and run, or reuse in your own app. Note that multiple samples packages are available — one for each Android platform version. When you are choosing a samples package to download, select the one whose API Level matches the API Level of the Android platform that you plan to use.

Tip: For easy access to the SDK tools from a command line, add the location of the SDK’s tools/ and platform-tools to your PATH environment variable.

The above list is not comprehensive and you can add new sites to download additional packages from third-parties.

Читайте также:  Все для андроид htc radar

In some cases, an SDK package may require a specific minimum revision of another package or SDK tool. The development tools will notify you with warnings if there is dependency that you need to address. The Android SDK Manager also enforces dependencies by requiring that you download any packages that are needed by those you have selected.

Adding New Sites

By default, Available Packages displays packages available from the Android Repository and Third party Add-ons. You can add other sites that host their own Android SDK add-ons, then download the SDK add-ons from those sites.

For example, a mobile carrier or device manufacturer might offer additional API libraries that are supported by their own Android-powered devices. In order to develop using their libraries, you must install their Android SDK add-on, if it’s not already available under Third party Add-ons.

If a carrier or device manufacturer has hosted an SDK add-on repository file on their web site, follow these steps to add their site to the Android SDK Manager:

  1. Select Available Packages in the left panel.
  2. Click Add Add-on Site and enter the URL of the repository.xml file. Click OK.

Any SDK packages available from the site will now be listed under a new item named User Add-ons.

Troubleshooting

Problems connecting to the SDK repository

If you are using the Android SDK Manager to download packages and are encountering connection problems, try connecting over http, rather than https. To switch the protocol used by the Android SDK Manager, follow these steps:

Источник

Adding SDK Packages

By default, the Android SDK does not include everything you need to start developing. The SDK separates tools, platforms, and other components into packages you can download as needed using the Android SDK Manager. So before you can start, there are a few packages you should add to your Android SDK.

To start adding packages, launch the Android SDK Manager in one of the following ways:

  • In Eclipse or Android Studio, click SDK Managerin the toolbar.
  • If you’re not using Eclipse or Android Studio:
    • Windows: Double-click the SDK Manager.exe file at the root of the Android SDK directory.
    • Mac/Linux: Open a terminal and navigate to the tools/ directory in the location where the Android SDK was installed, then execute android sdk .

When you open the SDK Manager for the first time, several packages will be selected by default. Leave these selected, but be sure you have everything you need to get started by following these steps:

Get the latest SDK tools

As a minimum when setting up the Android SDK, you should download the latest tools and Android platform:

  1. Open the Tools directory and select:
    • Android SDK Tools
    • Android SDK Platform-tools
    • Android SDK Build-tools (highest version)
  2. Open the first Android X.X folder (the latest version) and select:
    • SDK Platform
    • A system image for the emulator, such as
      ARM EABI v7a System Image

Get the support library for additional APIs

The support library is required for:

It also provides these popular APIs:

The Android Support Library provides an extended set of APIs that are compatible with most versions of Android.

Open the Extras directory and select:

  • Android Support Repository
  • Android Support Library

Get Google Play services for even more APIs

The Google Play services APIs provide a variety of features and services for your Android apps, such as:

To develop with Google APIs, you need the Google Play services package:

Open the Extras directory and select:

  • Google Repository
  • Google Play services

Note: Google Play services APIs are not available on all Android-powered devices, but are available on all devices with Google Play Store. To use these APIs in the Android emulator, you must also install the the Google APIs system image from the latest Android X.X directory in the SDK Manager.

Install the packages

Once you’ve selected all the desired packages, continue to install:

  1. Click Install X packages.
  2. In the next window, double-click each package name on the left to accept the license agreement for each.
  3. Click Install.

The download progress is shown at the bottom of the SDK Manager window. Do not exit the SDK Manager or it will cancel the download.

Читайте также:  Андроид тв флешка xiaomi

Build something!

With the above packages now in your Android SDK, you’re ready to build apps for Android. As new tools and other APIs become available, simply launch the SDK Manager to download the new packages for your SDK.

Here are a few options for how you should proceed:

Get started

If you’re new to Android development, learn the basics of Android apps by following the guide to Building Your First App.

Build for wearables

If you’re ready to start building apps for Android wearables, see the guide to Building Apps for Android Wear.

Use Google APIs

To start using Google APIs, such as Maps or Play Game services, see the guide to Setting Up Google Play Services.

Источник

Android SDK Quick Start Beta

Create a simple app that uses the Android SDK toВ play a playlist and subscribe to PlayerState.

This tutorial leads you step-by-step through the creation of a simple app that uses the Android SDK toВ play a playlist and subscribe to player state updates.

Introduction

This tutorial leads you step-by-step through the creation of a simple app that uses the Spotify App Remote SDKВ to play a playlist. We show you how to:

  • Play a playlist from a URI
  • Subscribe to PlayerState of the Spotify app and read its data

If you are new to developing Android apps, we recommend reading the tutorials on Google’s Android developer portal.

You can read more about the Android SDK in the overview, or dig into the reference documentation.

Prepare Your Environment

Register Your App

You will need to register your application on the Developer Dashboard and obtain a client ID. When you register your app you will also need to whitelist a redirect URI that the Spotify Accounts Service will use to callback to your app after authorization. You also should add your package name and app fingerprint as they’re used to verify the identity of your application.

Register App Fingerprints

Fingerprints are used for authentication between your Android Application and the Spotify service. You’ll need to generate a fingerprint for your app and register it in your Dashboard. We strongly recommend that you create both a development and a production fingerprint for security reasons.

To Create a Development Fingerprint

Run the following command in your Terminal and add a password when required:

You should expect to receive a fingerprint that looks like this: SHA1: E7:47:B5:45:71:A9:B4:47:EA:AD:21:D7:7C:A2:8D:B4:89:1C:BF:75

Copy the fingerprint and your package name and enter it in the Spotify Developer Dashboard, under the “Edit settings” section. Don’t forget to click Save after you added the fingerprints in the dashboard.

To Create a Release Fingerprint

The development and production versions of your application usually have different certificates for security reasons.

Run the following command in your Terminal (no password):

You should expect to receive a fingerprint that looks like this: SHA1: E7:47:B5:45:71:A9:B4:47:EA:AD:21:D7:7C:A2:8D:B4:89:1C:BF:75

Copy the fingerprint and your package name and enter it in the Spotify Developer Dashboard. Don’t forget to click Save after you added the fingerprints in the dashboard.

Install Spotify App

App Remote SDK requires the Spotify app to be installed on the device. Install the latest version of Spotify from Google Play on the device you want to use for development. Run the Spotify app and login or sign up.

Download the SDK

Download the Spotify Android SDK from our GitHub.

Create Your App

Create or make sure you have an Android app with at least one Activity or Service in which you can put yourВ code to connect to Spotify.

Edit your MainActivity to look like this:

Add the App Remote SDK

Unzip the App Remote SDK zip file that you downloaded. Add the library to your project by importing it as a module. In the “Project” side bar in Android Studio (View –> Tool Windows –> Project), right click your project’s root folder and navigate to “New” –> “Module”.

In the “New Module” window, choose the option “Import .JAR/AAR Package”. Click “Next”.

Press the “…” button and locate the spotify-app-remote-release-version.aar under the “app-remote-lib” folder in the unzipped bundle. Click “Open” and choose a suitable subproject name. We’re using spotify-app-remote in this example. Click “Finish” to import the .aar into your project.

Читайте также:  Super wallpaper для андроид

Tip: when updating the App Remote SDK with future updates of the SDK, simply replace the .aar file in your project’s directory.

Add a dependency on the spotify-app-remote module to your app by adding the imported subproject and Gson to your app’s build.gradle file. It is important that the name that you specify in the build.gradle file is the same as the subproject name you decided on.

Since version 0.2.0 of the App Remote SDK,В Gson is used by defaultВ for serializing and deserializing the request. Jackson is also supported. If you would like to use Jackson instead please see the FAQ here.

Import Dependencies

Set up your Spotify credentials

Authorize Your Application

To be able to use the App Remote SDK, the user needs to authorize your application to do so. If they haven’t, the connection will fail with UserNotAuthorizedException . To allow the user to authorize your app, you will use the built-in authorization described below.

The built-in authorization flow is an authorization method designed to make things easier for you. It only requires you to pass the corresponding parameters that you used when your application was created. Then, the Spotify client will attempt to authorize your app’s session and will use the ConnectionListener callback to send the authorization result.

For this use-case, you don’t have to add the Authorization Library to your application. You can request that the authorization view is shown to users who have not approved the app-remote-control scope by passing the flag showAuthView in the ConnectionParams . The scope is automatically requested for you by the library.

Add the following to your onStart method:

Built-in auth provides offline support. This means that a user can be authorized even if the device is currently offline. Offline support works out of the box, so it doesn’t require any additional implementation.

To successfully authorize a user while offline, the following conditions have to be met:

  • Your application has successfully connected to Spotify within the last 24 hours
  • Your application uses the same redirect URI, client ID and scopes when connecting to Spotify

Connect to App Remote

The first thing we need to do is to use the SpotifyAppRemote.Connector В to connect to Spotify and get an instance of SpotifyAppRemote . To do this, we call the SpotifyAppRemote.connect method using the connectionParams we defined above. Add the following to your onStart method.

Play a Playlist

To play a playlist given a Spotify playlist URI, we are going to connect to the Spotify app and use the PlayerApi В command. From there we can get the PlayerApi directly and call play. Add the following to your private connected method:

Run the application and you should hear some feel-good indie tunes playing on your phone. If you prefer something more relaxing, why not try some sweet piano music spotify:playlist:37i9dQZF1DX7K31D69s4M1 . If you don’t hear music playing and end up in the onFailure callback above, please read up on connection errors and try again.

Subscribe to PlayerState

The PlayerApi offers, in addition to the play(uri) method we use above, the ability to subscribe to and poll for the state of the Spotify player. Add the following to your code to subscribe to PlayerState and log the track title and artist of the song that will be playing:

Run the app again. You should now see a log with the track name and artist of the currently playing track.

Disconnecting from App Remote

Don’t forget to disconnect from App Remote when you no longer need it. Add the following to your onStop method.

Next Steps

Congratulations! You’ve interacted with the App Remote SDK for the first time. Time to celebrate, you did a great job! 👏

Want more? Here’s what you can do next:

  • Learn about best practices for handling App Remote SDK interactions and connections in your Android application in our guides.
  • Dive into other things you can do with the SDK in the App Remote SDK Reference.

Source Code

The Quick Start source code is below. Copy into your Main Activity.

Источник

Оцените статью