Java library receives current exchange rate
<dependency>
<groupId>com.posadskiy</groupId>
<artifactId>currency-converter</artifactId>
<version>1.1.3</version>
</dependency>
compile 'com.posadskiy:currency-converter:1.1.3'
libraryDependencies += "com.posadskiy" % "currency-converter" % "1.1.3"
/**
* Define your API keys
* Use at least one key, but we recommend define three:
* One or even two services can be off, but not three at the same time
*/
public static final String CURRENCY_CONVERTER_API_API_KEY = "YOUR API KEY FOR CurrencyConverterApi.Com";
public static final String CURRENCY_LAYER = "YOUR API KEY FOR CurrencyLayer.Com";
public static final String OPEN_EXCHANGE_RATES = "YOUR API KEY FOR OpenExchangeRates.Com";
// Init converter with your API key
CurrencyConverter converter = new CurrencyConverter(
new ConfigBuilder()
.currencyConverterApiApiKey(CURRENCY_CONVERTER_API_API_KEY)
.currencyLayerApiKey(CURRENCY_LAYER)
.openExchangeRatesApiKey(OPEN_EXCHANGE_RATES)
.build()
);
Sure, you are able to use only one service:
public static final String OPEN_EXCHANGE_RATES = "YOUR API KEY FOR OpenExchangeRates.Com";
CurrencyConverter converter = new CurrencyConverter(
new ConfigBuilder()
.openExchangeRatesApiKey(OPEN_EXCHANGE_RATES)
.build()
);
// Get rate with Currency Enum
Double gbrToChfRate = converter.rate(Currency.GBP, Currency.CHF);
// Get rate with half fixed method
Double usdToEuroRate = converter.rateFromUsd(Currency.EUR);
// Get rate with fixed method
Double usdToEuroRate = converter.rateFromUsdToEuro();
// Get rate with String parameters
Double usdToEuroRate = converter.rate("USD", "EUR");
Sing up on websites you are going to use:
and get key for use this services.
API key looks like symbolic string.
The working process for Android is different from the usual Java application. Network requests from the main tread are prohibited for Android, so a possible way to call Currency Converter library is by creating AsyncTask wrapper. See Examples.
Also, it should be noted, Android application should have permissions to interaction with Network. Add to AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
Currency Converter is available under the MIT license.