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.
git clone [email protected]:coinbase/coinbase-android-sdk.git
<activity android:name="com.bitmonet.coinbase.CoinbaseWebView"
android:theme="@android:style/Theme.NoTitleBar" />
initialize
API callsetReceivingAddress
API callrequestWalletAuthorization
call and implement the BitmonetOAuthStatusListener
interface to get the status of OAuth process. sendMoney
or the sendMoneyInBackground
API and implement the BitmonetPaymentStatusListener
interface to get the status of a transactionSample 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();
}
Initialize the SDK
/*
* Call this function to initialize the Bitmonet SDK. This function needs to
* be call before any API call.
*
* @param context Context of the application usign Bitmonet
*
* @param clientId ClientId value obtained from Coinbase
*
* @param clientSecret ClientSecret obtained from Coinbase
*
* @param callbackUrl Callback URL registered at Coinbase. Please ensure
* that the scheme used for the URL is unique to your application. The
* test application uses bitmonet://bitmonet. This is required to
* successfully redirect the user back to the app during the OAuth2 process
*/
public static void initialize(Context activtityContenxt, String clientId, String clientSecret, String callbackUrl)
Set the receiving address
/*
* Set the receiving address. This needs to set to the receive the Bitcoins.
*
* @param receivingAddress Bitcoin public address where all the bitcoins
* would be sent
*/
public static void setReceivingAddress(String receivingAddress)
Set the transaction currency
/*
* Set the transaction currency. The default currency is USD. But you can
* use any currency supported by Coinbase
*
* @param currency Currency to be shown to the customer and used during
* transactions
*/
public static void setTransactionCurrency(String currency)
Request Authorization to access the wallet
/*
* Request an Authorization from the user to access the wallet. This needs
* to be done only once, and Bitmonet takes care of refreshing the access
* token. Implement the BitmonetOAuthPaymentStatuslistener to get a
* notification on the completion of OAuth2 process.
*
* Before this method is called, ensure that Bitmonet has been initialized
* and CoinbaseWebview activity is declared in your manifest file.
*
* @param context Context of the activity from where this method is called.
*/
public static void requestWalletAuthorization(Context activityContext)
Transfer money from the user account to the specified receiving address
/*
* Send money to the specified address after asking for a confirmation from
* the user. This method transfers the money from the user's account to the
* receiving address set by the merchant. A modal is shown asking the user
* to confirm the transaction. Implement the BitmonetPaymentStatusListener
* to get the status of this call.
*
* Before this method can be called, ensure that Bitmonet is initialized,
* OAuth has been done, and a receiving address has been set.
*
* @param context Context of the calling activity. For e.g. use
* YourActivity.this as the value when calling this method.
*
* @param itemName Name of the item being purchased
*
* @param amount Amount to charged
*/
public static void sendMoney(Context activityContext, String itemName, double amount)
Transfer money from the user account to the specified receiving address without showing the modal
/*
* Send money to the specified address without showing the confirmation
* modal. This method transfers the money from the user's account to the
* receiving address set by the merchant. A modal is shown asking the user
* to confirm the transaction. Implement the BitmonetPaymentStatusListener
* to get the status of this call.
*
* Before this method can be called, ensure that Bitmonet is initialized,
* OAuth has been done, and a receiving address has been set.
*
* @param context Context of the calling activity. For e.g. use
* YourActivity.this as the value when calling this method.
*
* @param itemName Name of the item being purchased
*
* @param amount Amount to charged
*/
public static void sendMoneyInBackground(Context activityContext, String itemName, double amount)
Please use the SDK at your own discretion, and read the Google Play guidelines before publishing your app