Giter VIP home page Giter VIP logo

android-token-sharing's Introduction

Sharing sounds to SoundCloud via AccountManager

This is a small sample app to demonstrate how you could integrate SoundCloud in your own Android application. The official SoundCloud app for Android app needs to be installed, if it is missing the user will be asked to install it.

The demo app lets the user pick a piece of audio (using Android intents) which then gets uploaded to SoundCloud (as a private track).

How token sharing works

The integration uses the Android account manager to obtain a token and then makes requests using the standard SoundCloud Java API wrapper.

Here a very simplified usage pattern:

AccountManager accountManager = AccountManager.get(this);
Account[] acc = accountManager.getAccountsByType("com.soundcloud.android.account");
if (acc.length > 0) {
    // possibly ask user for permission to obtain token
    String access = accountManager.blockingGetAuthToken(acc[0], "access_token", true);
    Token token = new Token(access, null, Token.SCOPE_NON_EXPIRING);
    ApiWrapper wrapper = new ApiWrapper(null, null, null, token, Env.LIVE);

    HttpResponse resp = wrapper.get(Request.to("/me"));
    // do something with resp
} else {
    // logic to add an account
}

See the sample app for the detailed usage.

The big advantage of this approach is that you have full control over how you use the API, however the drawback of is that your app requires a few more permissions (android.permission.{GET_ACCOUNTS, MANAGE_ACCOUNTS, USE_CREDENTIALS}).

If you just want to upload a file to SoundCloud consider the Android intent sharing method instead.

Token invalidation

Once you have obtained a token from the account manager you should probably persist it in your app and only request a new token if necessary.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.