Coinbase Android SDK developed in collaboration with Bitmonet Open-source project is the first SDK that allows any Android developer to monetize their Android app with Bitcoins.

Features

  1. Monetize virtually anything with Bitcoins
  2. Accept payments with just one click
  3. Transfer money without showing the modal after receiving the authorization
  4. Seamless OAuth and token management

Set-up

  1. Create a Coinbase account and Register an App
  2. git clone [email protected]:coinbase/coinbase-android-sdk.git
  3. Import the code into your Android Workspace: File > Import... > Android > Existing Code into Android Workspace
  4. Add the bitmonet project as a library project to the App that you wish to monetize: Properties > Android > Library > Add
  5. Add the following two lines of code in your manifest file
<activity android:name="com.bitmonet.coinbase.CoinbaseWebView"
    android:theme="@android:style/Theme.NoTitleBar" />

Usage

  1. Initialize the SDK, when you initialize your app using the initialize API call
  2. Set the receiving address using the setReceivingAddress API call
  3. Request the user to access their wallet using requestWalletAuthorization call and implement the BitmonetOAuthStatusListener interface to get the status of OAuth process.
  4. To execute a transaction use the sendMoney or the sendMoneyInBackground API and implement the BitmonetPaymentStatusListener interface to get the status of a transaction

Sample implementation:


public class MainActivity extends Activity implements BitmonetPaymentStatusListener, BitmonetOAuthStatusListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.oauth_launcher);

        // Initialize the Bitmonet SDK
        Bitmonet.initialize(getApplicationContext(), "YOUR CLIENT ID", "YOUR CLIENT SECRET", "YOUR CALLBACK URL"); 

        // Set the address where you want to receive your Bitcoins
        Bitmonet.setReceivingAddress("YOUR RECEIVING ADDRESS");

        // Set the transaction currency
        Bitmonet.setTransactionCurrency("BTC");

        Button authorize = (Button) findViewById(R.id.button1);
        authorize.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Request Wallet Authorization
                Bitmonet.requestWalletAuthorization(MainActivity.this);
            }
        });

        Button sendMoney = (Button) findViewById(R.id.button2);
        sendMoney.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Send money and ask the user for a confirmation
                Bitmonet.sendMoney(MainActivity.this, "1000 Gold", 0.001);
            }
        });

        Button sendMoneyInBackground = (Button) findViewById(R.id.button3);
        sendMoneyInBackground.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Send money in the background
                Bitmonet.sendMoneyInBackground(MainActivity.this, "1000 Gold", 0.001);
            }
        });

        Button sendMoneyError = (Button) findViewById(R.id.button4);
        sendMoneyError.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Generate an error in the sendmoney call
                Bitmonet.sendMoney(MainActivity.this, "1000 Gold", 0.00000001);
            }
        });

    }

    @Override
    public void paymentFailure(String[] errors) {
        String displayError = "";

        for (int i = 0; i < errors.length; i++) {
            displayError = displayError + errors[i] + " ";
        }

        Toast.makeText(getApplicationContext(), "Errors: " + displayError, Toast.LENGTH_LONG).show();
    }

    @Override
    public void walletOAuthStatusListener(boolean status) {
        Toast.makeText(getApplicationContext(), "OAuth Complete: " + String.valueOf(status), Toast.LENGTH_LONG).show();
    }

    @Override
    public void paymentSuccess(String hash) {
        Toast.makeText(getApplicationContext(), "Transaction Hash: " + hash, Toast.LENGTH_LONG).show();
    }

API

Warning

Please use the SDK at your own discretion, and read the Google Play guidelines before publishing your app