private void attemptEncrypt() {
    mPlaintextView.setError(null);
    mCiphertextView.setError(null);
    mCiphertextView.setText("");

    try {
      byte[] plaintext = mPlaintextView.getText().toString().getBytes(StandardCharsets.UTF_8);
      // An artifical step to test whether Tink can co-exist with protobuf-lite.
      ByteString pStr = ByteString.copyFrom(plaintext);
      byte[] associatedData =
          mAssociatedDataView.getText().toString().getBytes(StandardCharsets.UTF_8);
      byte[] ciphertext = mApplication.aead.encrypt(pStr.toByteArray(), associatedData);
      mCiphertextView.setText(base64Encode(ciphertext));
    } catch (GeneralSecurityException | IllegalArgumentException e) {
      mCiphertextView.setError(
          String.format("%s: %s", getString(R.string.error_cannot_encrypt), e.toString()));
      mPlaintextView.requestFocus();
    }
  }
This activity allows users to encrypt and decrypt a string.
java_src/examples/android/helloworld/app/src/main/java/com/helloworld/MainActivity.java