Search in sources :

Example 1 with BitcoinURI

use of org.bitcoinj.uri.BitcoinURI in project bitcoin-wallet by bitcoin-wallet.

the class SendingAddressesFragment method getAddressFromPrimaryClip.

private Address getAddressFromPrimaryClip() {
    if (!clipboardManager.hasPrimaryClip())
        return null;
    final ClipData clip = clipboardManager.getPrimaryClip();
    final ClipDescription clipDescription = clip.getDescription();
    if (clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
        final CharSequence clipText = clip.getItemAt(0).getText();
        if (clipText == null)
            return null;
        try {
            return Address.fromBase58(Constants.NETWORK_PARAMETERS, clipText.toString().trim());
        } catch (final AddressFormatException x) {
            return null;
        }
    } else if (clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_URILIST)) {
        final Uri clipUri = clip.getItemAt(0).getUri();
        if (clipUri == null)
            return null;
        try {
            return new BitcoinURI(clipUri.toString()).getAddress();
        } catch (final BitcoinURIParseException x) {
            return null;
        }
    } else {
        return null;
    }
}
Also used : AddressFormatException(org.bitcoinj.core.AddressFormatException) BitcoinURI(org.bitcoinj.uri.BitcoinURI) ClipData(android.content.ClipData) Uri(android.net.Uri) BitcoinURIParseException(org.bitcoinj.uri.BitcoinURIParseException) ClipDescription(android.content.ClipDescription)

Aggregations

ClipData (android.content.ClipData)1 ClipDescription (android.content.ClipDescription)1 Uri (android.net.Uri)1 AddressFormatException (org.bitcoinj.core.AddressFormatException)1 BitcoinURI (org.bitcoinj.uri.BitcoinURI)1 BitcoinURIParseException (org.bitcoinj.uri.BitcoinURIParseException)1