Example usage for android.content Intent getByteArrayExtra

List of usage examples for android.content Intent getByteArrayExtra

Introduction

In this page you can find the example usage for android.content Intent getByteArrayExtra.

Prototype

public byte[] getByteArrayExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:org.thialfihar.android.apg.ui.ImportKeysActivity.java

protected void handleActions(Bundle savedInstanceState, Intent intent) {
    String action = intent.getAction();
    Bundle extras = intent.getExtras();/*from ww w .  j  av a2 s .  c o m*/
    Uri dataUri = intent.getData();
    String scheme = intent.getScheme();

    if (extras == null) {
        extras = new Bundle();
    }

    if (Intent.ACTION_VIEW.equals(action)) {
        // Android's Action when opening file associated to Keychain (see AndroidManifest.xml)
        // override action to delegate it to Keychain's ACTION_IMPORT_KEY
        action = ACTION_IMPORT_KEY;
    }

    if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) {
        /* Scanning a fingerprint directly with Barcode Scanner */
        loadFromFingerprintUri(savedInstanceState, dataUri);
    } else if (ACTION_IMPORT_KEY.equals(action)) {
        /* Keychain's own Actions */

        // display file fragment
        loadNavFragment(1, null);

        if (dataUri != null) {
            // action: directly load data
            startListFragment(savedInstanceState, null, dataUri, null);
        } else if (extras.containsKey(EXTRA_KEY_BYTES)) {
            byte[] importData = intent.getByteArrayExtra(EXTRA_KEY_BYTES);

            // action: directly load data
            startListFragment(savedInstanceState, importData, null, null);
        }
    } else if (ACTION_IMPORT_KEY_FROM_KEYSERVER.equals(action)) {
        String query = null;
        if (extras.containsKey(EXTRA_QUERY)) {
            query = extras.getString(EXTRA_QUERY);
        } else if (extras.containsKey(EXTRA_KEY_ID)) {
            long keyId = intent.getLongExtra(EXTRA_KEY_ID, 0);
            if (keyId != 0) {
                query = PgpKeyHelper.convertKeyIdToHex(keyId);
            }
        } else if (extras.containsKey(EXTRA_FINGERPRINT)) {
            String fingerprint = intent.getStringExtra(EXTRA_FINGERPRINT);
            if (fingerprint != null) {
                query = "0x" + fingerprint;
            }
        } else {
            Log.e(Constants.TAG, "IMPORT_KEY_FROM_KEYSERVER action needs to contain the 'query', "
                    + "'key_id', or 'fingerprint' extra!");
            return;
        }

        // display keyserver fragment with query
        Bundle args = new Bundle();
        args.putString(ImportKeysServerFragment.ARG_QUERY, query);
        loadNavFragment(0, args);

        // action: search immediately
        startListFragment(savedInstanceState, null, null, query);
    } else if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) {

        // NOTE: this only displays the appropriate fragment, no actions are taken
        loadNavFragment(1, null);

        // no immediate actions!
        startListFragment(savedInstanceState, null, null, null);
    } else if (ACTION_IMPORT_KEY_FROM_QR_CODE.equals(action)) {
        // also exposed in AndroidManifest

        // NOTE: this only displays the appropriate fragment, no actions are taken
        loadNavFragment(2, null);

        // no immediate actions!
        startListFragment(savedInstanceState, null, null, null);
    } else if (ACTION_IMPORT_KEY_FROM_NFC.equals(action)) {

        // NOTE: this only displays the appropriate fragment, no actions are taken
        loadNavFragment(3, null);

        // no immediate actions!
        startListFragment(savedInstanceState, null, null, null);
    } else {
        startListFragment(savedInstanceState, null, null, null);
    }
}

From source file:com.hivewallet.androidclient.wallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent != null) {
        log.info("service start command: " + intent
                + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                        ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                        : ""));

        final String action = intent.getAction();

        if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
            nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
        } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
            log.info("will remove blockchain on service shutdown");

            resetBlockchainOnShutdown = true;
            stopSelf();/*from   w  w  w.j av a 2 s  . com*/
        } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
            final Sha256Hash hash = new Sha256Hash(
                    intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
            final Transaction tx = application.getWallet().getTransaction(hash);

            if (peerGroup != null) {
                log.info("broadcasting transaction " + tx.getHashAsString());
                peerGroup.broadcastTransaction(tx);
            } else {
                log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
            }
        }
    } else {
        log.warn("service restart, although it was started as non-sticky");
    }

    return START_NOT_STICKY;
}

From source file:com.blu3f1re.reddwallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    log.info("service start command: " + intent
            + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                    ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                    : ""));

    final String action = intent.getAction();

    if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
        notificationCount = 0;/*from   w w  w  .  j  a  v a2  s. c  o  m*/
        notificationAccumulatedAmount = BigInteger.ZERO;
        notificationAddresses.clear();

        nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
    } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
        log.info("will remove blockchain on service shutdown");

        resetBlockchainOnShutdown = true;
        stopSelf();
    } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
        final Sha256Hash hash = new Sha256Hash(
                intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
        final Transaction tx = application.getWallet().getTransaction(hash);

        if (peerGroup != null) {
            log.info("broadcasting transaction " + tx.getHashAsString());
            peerGroup.broadcastTransaction(tx);
        } else {
            log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
        }
    }

    return START_NOT_STICKY;
}

From source file:com.tribesman.wallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent != null) {
        log.info("service start command: " + intent
                + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                        ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                        : ""));

        final String action = intent.getAction();

        if (ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
            notificationCount = 0;//w  w  w . j  ava 2  s  .c  o m
            notificationAccumulatedAmount = BigInteger.ZERO;
            notificationAddresses.clear();

            nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
        } else if (ACTION_RESET_BLOCKCHAIN.equals(action)) {
            log.info("will remove blockchain on service shutdown");

            resetBlockchainOnShutdown = true;
            stopSelf();
        } else if (ACTION_BROADCAST_TRANSACTION.equals(action)) {
            final Sha256Hash hash = new Sha256Hash(intent.getByteArrayExtra(ACTION_BROADCAST_TRANSACTION_HASH));
            final Transaction tx = application.getWallet().getTransaction(hash);

            if (peerGroup != null) {
                log.info("broadcasting transaction " + tx.getHashAsString());
                peerGroup.broadcastTransaction(tx);
            } else {
                log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
            }
        }
    } else {
        log.warn("service restart, although it was started as non-sticky");
    }

    return START_NOT_STICKY;
}

From source file:org.metawatch.manager.MetaWatchService.java

@Override
public synchronized int onStartCommand(final Intent intent, int flags, int startId) {
    if (Preferences.logging)
        Log.d(MetaWatchStatus.TAG, "MetaWatchService.onStartCommand()");
    if (intent != null) {
        switch (intent.getIntExtra(COMMAND_KEY, -1)) {
        case SILENT_MODE_ENABLE:
            setSilentMode(true);//  w  ww  . ja va  2s.c  om
            break;
        case SILENT_MODE_DISABLE:
            setSilentMode(false);
            break;
        case INVERT_SILENT_MODE:
            setSilentMode(!silentMode);
            break;
        case SEND_BYTE_ARRAY:
            sendQueue.add(intent.getByteArrayExtra(BYTE_ARRAY));
            break;
        }
    }
    return Service.START_STICKY;
}

From source file:org.hopestarter.wallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent != null) {
        log.info("service start command: " + intent
                + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                        ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                        : ""));

        final String action = intent.getAction();

        if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
            notificationCount = 0;//ww  w  .j a v  a  2 s . co m
            notificationAccumulatedAmount = Coin.ZERO;
            notificationAddresses.clear();

            nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
        } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
            log.info("will remove blockchain on service shutdown");

            resetBlockchainOnShutdown = true;
            stopSelf();
        } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
            final Sha256Hash hash = Sha256Hash
                    .wrap(intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
            final Transaction tx = application.getWallet().getTransaction(hash);

            if (peerGroup != null) {
                log.info("broadcasting transaction " + tx.getHashAsString());
                peerGroup.broadcastTransaction(tx);
            } else {
                log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
            }
        }
    } else {
        log.warn("service restart, although it was started as non-sticky");
    }

    return START_NOT_STICKY;
}

From source file:biz.wiz.android.wallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent != null) {
        log.info("service start command: " + intent
                + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                        ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                        : ""));

        final String action = intent.getAction();

        if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
            notificationCount = 0;/*  ww w.  j a va 2s.  com*/
            notificationAccumulatedAmount = Coin.ZERO;
            notificationAddresses.clear();

            nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
        } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
            log.info("will remove blockchain on service shutdown");

            resetBlockchainOnShutdown = true;
            stopSelf();
        } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
            final Sha256Hash hash = new Sha256Hash(
                    intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
            final Transaction tx = application.getWallet().getTransaction(hash);

            if (peerGroup != null) {
                log.info("broadcasting transaction " + tx.getHashAsString());
                peerGroup.broadcastTransaction(tx);
            } else {
                log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
            }
        }
    } else {
        log.warn("service restart, although it was started as non-sticky");
    }

    return START_NOT_STICKY;
}

From source file:de.schildbach.litecoinwallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    final String action = intent.getAction();

    if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
        notificationCount = 0;// www. ja  v a  2 s. c o m
        notificationAccumulatedAmount = BigInteger.ZERO;
        notificationAddresses.clear();

        nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
    }

    if (BlockchainService.ACTION_HOLD_WIFI_LOCK.equals(action)) {
        log.debug("acquiring wifilock");
        wifiLock.acquire();
    } else {
        log.debug("releasing wifilock");
        wifiLock.release();
    }

    if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
        log.info("will remove blockchain on service shutdown");

        resetBlockchainOnShutdown = true;
        stopSelf();
    }

    if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
        final Sha256Hash hash = new Sha256Hash(
                intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
        final Transaction tx = application.getWallet().getTransaction(hash);

        if (peerGroup != null) {
            log.info("broadcasting transaction " + tx.getHashAsString());
            peerGroup.broadcastTransaction(tx);
        } else {
            log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
        }
    }

    return START_NOT_STICKY;
}

From source file:com.hamradiocoin.wallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent != null) {
        log.info("service start command: " + intent
                + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                        ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                        : ""));

        final String action = intent.getAction();

        if (ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
            notificationCount = 0;//from   w ww. jav  a 2  s  . c  o m
            notificationAccumulatedAmount = BigInteger.ZERO;
            notificationAddresses.clear();
            nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
        } else if (ACTION_RESET_BLOCKCHAIN.equals(action)) {
            log.info("will remove blockchain on service shutdown");

            resetBlockchainOnShutdown = true;
            stopSelf();
        } else if (ACTION_BROADCAST_TRANSACTION.equals(action)) {
            final Sha256Hash hash = new Sha256Hash(intent.getByteArrayExtra(ACTION_BROADCAST_TRANSACTION_HASH));
            final Transaction tx = application.getWallet().getTransaction(hash);

            if (peerGroup != null) {
                log.info("broadcasting transaction " + tx.getHashAsString());
                peerGroup.broadcastTransaction(tx);
            } else {
                log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
            }
        }
    } else {
        log.warn("service restart, although it was started as non-sticky");
    }

    return START_NOT_STICKY;
}

From source file:org.sufficientlysecure.keychain.ui.keyview.ViewKeyActivity.java

@Override
protected void onActivityResult(@RequestType int requestCode, int resultCode, Intent data) {
    if (mImportOpHelper.handleActivityResult(requestCode, resultCode, data)) {
        return;/*from   w  w  w.j  av a  2s  .  c  om*/
    }
    if (mEditOpHelper != null) {
        mEditOpHelper.handleActivityResult(requestCode, resultCode, data);
    }

    if (resultCode != Activity.RESULT_OK) {
        super.onActivityResult(requestCode, resultCode, data);
        return;
    }

    switch (requestCode) {
    case REQUEST_QR_FINGERPRINT: {

        // If there is an EXTRA_RESULT, that's an error. Just show it.
        if (data.hasExtra(OperationResult.EXTRA_RESULT)) {
            OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT);
            result.createNotify(this).show();
            return;
        }

        byte[] fingerprint = data.getByteArrayExtra(ImportKeysProxyActivity.EXTRA_FINGERPRINT);
        if (fingerprint == null) {
            Notify.create(this, R.string.error_scan_fp, Notify.LENGTH_LONG, Style.ERROR).show();
            return;
        }
        if (Arrays.equals(mFingerprint, fingerprint)) {
            certifyImmediate();
        } else {
            Notify.create(this, R.string.error_scan_match, Notify.LENGTH_LONG, Style.ERROR).show();
        }
        return;
    }

    case REQUEST_BACKUP: {
        startBackupActivity();
        return;
    }

    case REQUEST_DELETE: {
        setResult(RESULT_OK, data);
        finish();
        return;
    }

    case REQUEST_CERTIFY: {
        if (data.hasExtra(OperationResult.EXTRA_RESULT)) {
            OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT);
            result.createNotify(this).show();
        }
        return;
    }

    }

    super.onActivityResult(requestCode, resultCode, data);

}