コード例 #1
0
  private void shareKey(Uri dataUri, boolean fingerprintOnly) {
    String content;
    if (fingerprintOnly) {
      byte[] fingerprintBlob = ProviderHelper.getFingerprint(this, dataUri);
      String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, false);

      content = Constants.FINGERPRINT_SCHEME + ":" + fingerprint;
    } else {
      // get public keyring as ascii armored string
      long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
      ArrayList<String> keyringArmored =
          ProviderHelper.getKeyRingsAsArmoredString(this, dataUri, new long[] {masterKeyId});

      content = keyringArmored.get(0);

      // Android will fail with android.os.TransactionTooLargeException if key is too big
      // see http://www.lonestarprod.com/?p=34
      if (content.length() >= 86389) {
        Toast.makeText(getApplicationContext(), R.string.key_too_big_for_sharing, Toast.LENGTH_LONG)
            .show();
        return;
      }
    }

    // let user choose application
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, content);
    sendIntent.setType("text/plain");
    startActivity(
        Intent.createChooser(sendIntent, getResources().getText(R.string.action_share_key_with)));
  }
コード例 #2
0
  private void copyToClipboard(Uri dataUri) {
    // get public keyring as ascii armored string
    long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
    ArrayList<String> keyringArmored =
        ProviderHelper.getKeyRingsAsArmoredString(this, dataUri, new long[] {masterKeyId});

    ClipboardReflection.copyToClipboard(this, keyringArmored.get(0));
    Toast.makeText(getApplicationContext(), R.string.key_copied_to_clipboard, Toast.LENGTH_LONG)
        .show();
  }