Example usage for android.os Bundle putByteArray

List of usage examples for android.os Bundle putByteArray

Introduction

In this page you can find the example usage for android.os Bundle putByteArray.

Prototype

@Override
public void putByteArray(@Nullable String key, @Nullable byte[] value) 

Source Link

Document

Inserts a byte array value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:com.facebook.android.Example.java

/** Called when the activity is first created. */
@Override//  w  ww.  j  av  a 2  s .co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (APP_ID == null) {
        Util.showAlert(this, "Warning",
                "Facebook Applicaton ID must be " + "specified before running this example: see Example.java");
    }

    setContentView(R.layout.main);
    mLoginButton = (LoginButton) findViewById(R.id.login);
    mText = (TextView) Example.this.findViewById(R.id.txt);
    mRequestButton = (Button) findViewById(R.id.requestButton);
    mPostButton = (Button) findViewById(R.id.postButton);
    mDeleteButton = (Button) findViewById(R.id.deletePostButton);
    mUploadButton = (Button) findViewById(R.id.uploadButton);

    mFacebook = new Facebook(APP_ID);
    mAsyncRunner = new AsyncFacebookRunner(mFacebook);

    SessionStore.restore(mFacebook, this);
    SessionEvents.addAuthListener(new SampleAuthListener());
    SessionEvents.addLogoutListener(new SampleLogoutListener());
    mLoginButton.init(this, mFacebook);

    mRequestButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mAsyncRunner.request("me", new SampleRequestListener());
        }
    });
    mRequestButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mUploadButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Bundle params = new Bundle();
            params.putString("method", "photos.upload");

            URL uploadFileUrl = null;
            try {
                uploadFileUrl = new URL("http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            try {
                HttpURLConnection conn = (HttpURLConnection) uploadFileUrl.openConnection();
                conn.setDoInput(true);
                conn.connect();
                int length = conn.getContentLength();

                byte[] imgData = new byte[length];
                InputStream is = conn.getInputStream();
                is.read(imgData);
                params.putByteArray("picture", imgData);

            } catch (IOException e) {
                e.printStackTrace();
            }

            mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
        }
    });
    mUploadButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mPostButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mFacebook.dialog(Example.this, "feed", new SampleDialogListener());
        }
    });
    mPostButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);
}

From source file:com.charabia.SmsViewActivity.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt("mode", mode);
    outState.putString("prefPhoneNumber", prefPhoneNumber);
    outState.putSerializable("keypair", keypair);
    outState.putByteArray("key", key);
    outState.putString("phoneNumber", phoneNumber);
}

From source file:com.jittr.android.facebook.Example.java

/** Called when the activity is first created. */
@Override//from w  ww.  j  a v  a  2s. c o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (APP_ID == null) {
        Util.showAlert(this, "Warning",
                "Facebook Applicaton ID must be " + "specified before running this example: see Example.java");
    }

    // mFacebook.
    setContentView(R.layout.mainfacebook);
    mLoginButton = (LoginButton) findViewById(R.id.login);
    mText = (TextView) Example.this.findViewById(R.id.txt);
    mRequestButton = (Button) findViewById(R.id.requestButton);
    mPostButton = (Button) findViewById(R.id.postButton);
    mDeleteButton = (Button) findViewById(R.id.deletePostButton);
    mUploadButton = (Button) findViewById(R.id.uploadButton);

    mFacebook = new Facebook();
    mAsyncRunner = new AsyncFacebookRunner(mFacebook);

    SessionStore.restore(mFacebook, this);
    SessionEvents.addAuthListener(new SampleAuthListener());
    SessionEvents.addLogoutListener(new SampleLogoutListener());
    mLoginButton.init(mFacebook, PERMISSIONS);

    mRequestButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mAsyncRunner.request("me", new SampleRequestListener());
        }
    });
    mRequestButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mUploadButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Bundle params = new Bundle();
            params.putString("method", "photos.upload");

            URL uploadFileUrl = null;
            try {
                uploadFileUrl = new URL("http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            try {
                HttpURLConnection conn = (HttpURLConnection) uploadFileUrl.openConnection();
                conn.setDoInput(true);
                conn.connect();
                int length = conn.getContentLength();

                byte[] imgData = new byte[length];
                InputStream is = conn.getInputStream();
                is.read(imgData);
                params.putByteArray("picture", imgData);

            } catch (IOException e) {
                e.printStackTrace();
            }

            mAsyncRunner.request(null, params, "POST", new SampleUploadListener());
        }
    });
    mUploadButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mPostButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mFacebook.dialog(Example.this, "stream.publish", new SampleDialogListener());
        }
    });
    mPostButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);
}

From source file:edu.stanford.mobisocial.dungbeetle.facebook.FacebookInterfaceActivity.java

/** Called when the activity is first created. */
@Override/*w w  w . ja  va  2  s.  com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (APP_ID == null) {
        Util.showAlert(this, "Warning", "Facebook Applicaton ID must be "
                + "specified before running this example: see FacebookInterfaceActivity.java");
    }

    setContentView(R.layout.facebook);
    mLoginButton = (LoginButton) findViewById(R.id.login);
    mText = (TextView) FacebookInterfaceActivity.this.findViewById(R.id.txt);
    mRequestButton = (Button) findViewById(R.id.requestButton);
    mPostButton = (Button) findViewById(R.id.postButton);
    mDeleteButton = (Button) findViewById(R.id.deletePostButton);
    mUploadButton = (Button) findViewById(R.id.uploadButton);

    mFacebook = new Facebook(APP_ID);
    mAsyncRunner = new AsyncFacebookRunner(mFacebook);

    SessionStore.restore(mFacebook, this);
    SessionEvents.addAuthListener(new SampleAuthListener());
    SessionEvents.addLogoutListener(new SampleLogoutListener());
    mLoginButton.init(this, mFacebook);

    mRequestButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mAsyncRunner.request("me", new SampleRequestListener());
        }
    });
    mRequestButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mUploadButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Bundle params = new Bundle();
            params.putString("method", "photos.upload");

            URL uploadFileUrl = null;
            try {
                uploadFileUrl = new URL("http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            try {
                HttpURLConnection conn = (HttpURLConnection) uploadFileUrl.openConnection();
                conn.setDoInput(true);
                conn.connect();
                int length = conn.getContentLength();

                byte[] imgData = new byte[length];
                InputStream is = conn.getInputStream();
                is.read(imgData);
                params.putByteArray("picture", imgData);

            } catch (IOException e) {
                e.printStackTrace();
            }

            mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
        }
    });
    mUploadButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mPostButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mFacebook.dialog(FacebookInterfaceActivity.this, "feed", new SampleDialogListener());
        }
    });
    mPostButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);
}

From source file:com.pixem.core.activity.Example.java

/** Called when the activity is first created. */
@Override/*from w  w w  . j  a  v a  2s .co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (APP_ID == null) {
        Util.showAlert(this, "Warning",
                "Facebook Applicaton ID must be " + "specified before running this example: see Example.java");
    }

    setContentView(R.layout.facebook);
    mLoginButton = (LoginButton) findViewById(R.id.login);
    mText = (TextView) Example.this.findViewById(R.id.txt);
    mRequestButton = (Button) findViewById(R.id.requestButton);
    mPostButton = (Button) findViewById(R.id.postButton);
    mDeleteButton = (Button) findViewById(R.id.deletePostButton);
    mUploadButton = (Button) findViewById(R.id.uploadButton);

    mFacebook = new Facebook(APP_ID);
    mAsyncRunner = new AsyncFacebookRunner(mFacebook);

    SessionStore.restore(mFacebook, this);
    SessionEvents.addAuthListener(new SampleAuthListener());
    SessionEvents.addLogoutListener(new SampleLogoutListener());
    mLoginButton.init(this, mFacebook);

    mRequestButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mAsyncRunner.request("me", new SampleRequestListener());
        }
    });
    mRequestButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mUploadButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Bundle params = new Bundle();
            params.putString("method", "photos.upload");

            URL uploadFileUrl = null;
            try {
                uploadFileUrl = new URL("http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            try {
                HttpURLConnection conn = (HttpURLConnection) uploadFileUrl.openConnection();
                conn.setDoInput(true);
                conn.connect();
                int length = conn.getContentLength();

                byte[] imgData = new byte[length];
                InputStream is = conn.getInputStream();
                is.read(imgData);
                params.putByteArray("picture", imgData);

            } catch (IOException e) {
                e.printStackTrace();
            }

            mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
        }
    });
    mUploadButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mPostButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mFacebook.dialog(Example.this, "feed", new SampleDialogListener());
        }
    });
    mPostButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);
}

From source file:id.nci.stm_9.ImportKeysActivity.java

/**
 * Import keys with mImportData// w  ww .jav a2s  . c  o  m
 */
public void importKeys() {
    if (mListFragment.getKeyBytes() != null || mListFragment.getImportFilename() != null) {
        Log.d("stm-9", "importKeys started");

        // Send all information needed to service to import key in other thread
        Intent intent = new Intent(this, KeychainIntentService.class);

        intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);

        // fill values for this action
        Bundle data = new Bundle();

        // get selected key ids
        List<ImportKeysListEntry> listEntries = mListFragment.getData();
        ArrayList<Long> selectedKeyIds = new ArrayList<Long>();
        for (ImportKeysListEntry entry : listEntries) {
            if (entry.isSelected()) {
                selectedKeyIds.add(entry.keyId);
            }
        }

        data.putSerializable(KeychainIntentService.IMPORT_KEY_LIST, selectedKeyIds);

        if (mListFragment.getKeyBytes() != null) {
            data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_BYTES);
            data.putByteArray(KeychainIntentService.IMPORT_BYTES, mListFragment.getKeyBytes());
        } else {
            data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_FILE);
            data.putString(KeychainIntentService.IMPORT_FILENAME, mListFragment.getImportFilename());
        }

        intent.putExtra(KeychainIntentService.EXTRA_DATA, data);

        // Message is received after importing is done in ApgService
        KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this,
                R.string.progress_importing, ProgressDialog.STYLE_HORIZONTAL) {
            public void handleMessage(Message message) {
                // handle messages by standard ApgHandler first
                super.handleMessage(message);

                if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
                    // get returned data bundle
                    Bundle returnData = message.getData();

                    int added = returnData.getInt(KeychainIntentService.RESULT_IMPORT_ADDED);
                    int updated = returnData.getInt(KeychainIntentService.RESULT_IMPORT_UPDATED);
                    //                        int bad = returnData.getInt(KeychainIntentService.RESULT_IMPORT_BAD);
                    String toastMessage;
                    if (added > 0 && updated > 0) {
                        toastMessage = getString(R.string.keys_added_and_updated, added, updated);
                    } else if (added > 0) {
                        toastMessage = getString(R.string.keys_added, added);
                    } else if (updated > 0) {
                        toastMessage = getString(R.string.keys_updated, updated);
                    } else {
                        toastMessage = getString(R.string.no_keys_added_or_updated);
                    }
                    Toast.makeText(ImportKeysActivity.this, toastMessage, Toast.LENGTH_SHORT).show();
                    //                        if (bad > 0) {
                    //                            AlertDialog.Builder alert = new AlertDialog.Builder(
                    //                                    ImportKeysActivity.this);
                    //
                    //                            alert.setIcon(android.R.drawable.ic_dialog_alert);
                    //                            alert.setTitle(R.string.warning);
                    //                            alert.setMessage(ImportKeysActivity.this.getString(
                    //                                    R.string.bad_keys_encountered, bad));
                    //
                    //                            alert.setPositiveButton(android.R.string.ok,
                    //                                    new DialogInterface.OnClickListener() {
                    //                                        public void onClick(DialogInterface dialog, int id) {
                    //                                            dialog.cancel();
                    //                                        }
                    //                                    });
                    //                            alert.setCancelable(true);
                    //                            alert.create().show();
                    //                        } else if (mDeleteAfterImport) {
                    //                            // everything went well, so now delete, if that was turned on
                    //                            DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment
                    //                                    .newInstance(mListFragment.getImportFilename());
                    //                            deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
                    //                        }
                }
            };
        };

        // Create a new Messenger for the communication back
        Messenger messenger = new Messenger(saveHandler);
        intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);

        // show progress dialog
        saveHandler.showProgressDialog(this);

        // start service with intent
        startService(intent);
    } else {
        Toast.makeText(this, R.string.error_nothing_import, Toast.LENGTH_LONG).show();
    }
}

From source file:com.shurik.droidzebra.DroidZebra.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    ZebraEngine.GameState gs = mZebraThread.getGameState();
    if (gs != null) {
        outState.putByteArray("moves_played", gs.mMoveSequence);
        outState.putInt("moves_played_count", gs.mDisksPlayed);
        outState.putInt("version", 1);
    }/*from  w  w  w . j a va 2 s  .  c  o m*/
}

From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    if (mLyrics != null)
        try {/*from   ww  w  .j a va2  s .  co m*/
            outState.putByteArray("lyrics", mLyrics.toBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    View searchView = getActivity().findViewById(R.id.search_view);
    if (searchView instanceof SearchView) {
        outState.putString("searchQuery", ((SearchView) searchView).getQuery().toString());
        outState.putBoolean("searchFocused", searchView.hasFocus());
    }

    outState.putBoolean("refreshFabEnabled", getActivity().findViewById(R.id.refresh_fab).isEnabled());

    EditText editedLyrics = (EditText) getActivity().findViewById(R.id.edit_lyrics);
    if (editedLyrics.getVisibility() == View.VISIBLE) {
        EditText editedTitle = (EditText) getActivity().findViewById(R.id.song);
        EditText editedArtist = (EditText) getActivity().findViewById(R.id.artist);
        outState.putCharSequence("editedLyrics", editedLyrics.getText());
        outState.putCharSequence("editedTitle", editedTitle.getText());
        outState.putCharSequence("editedArtist", editedArtist.getText());
    }
}

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

private void encryptStart(final boolean toClipboard) {
    // Send all information needed to service to edit key in other thread
    Intent intent = new Intent(getActivity(), ApgIntentService.class);

    intent.setAction(ApgIntentService.ACTION_ENCRYPT_SIGN);

    // fill values for this action
    Bundle data = new Bundle();

    data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_BYTES);

    String message = mMessage.getText().toString();

    if (mEncryptInterface.isModeSymmetric()) {
        Log.d(Constants.TAG, "Symmetric encryption enabled!");
        String passphrase = mEncryptInterface.getPassphrase();
        if (passphrase.length() == 0) {
            passphrase = null;//from   w  w w  .  j a  v a 2 s  .c o m
        }
        data.putString(ApgIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase);
    } else {
        data.putLong(ApgIntentService.ENCRYPT_SIGNATURE_KEY_ID, mEncryptInterface.getSignatureKey());
        data.putLongArray(ApgIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, mEncryptInterface.getEncryptionKeys());

        boolean signOnly = (mEncryptInterface.getEncryptionKeys() == null
                || mEncryptInterface.getEncryptionKeys().length == 0);
        if (signOnly) {
            message = fixBadCharactersForGmail(message);
        }
    }

    data.putByteArray(ApgIntentService.ENCRYPT_MESSAGE_BYTES, message.getBytes());

    data.putBoolean(ApgIntentService.ENCRYPT_USE_ASCII_ARMOR, true);

    int compressionId = Preferences.getPreferences(getActivity()).getDefaultMessageCompression();
    data.putInt(ApgIntentService.ENCRYPT_COMPRESSION_ID, compressionId);

    intent.putExtra(ApgIntentService.EXTRA_DATA, data);

    final Activity activity = getActivity();
    // Message is received after encrypting is done in ApgIntentService
    ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(getActivity(),
            getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) {
        public void handleMessage(Message message) {
            // handle messages by standard ApgIntentServiceHandler first
            super.handleMessage(message);

            if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
                // get returned data bundle
                Bundle data = message.getData();

                String output = new String(data.getByteArray(ApgIntentService.RESULT_BYTES));
                Log.d(Constants.TAG, "output: " + output);

                if (mLegacyMode) {
                    Intent result = new Intent();
                    result.putExtra("encryptedMessage", output);
                    activity.setResult(activity.RESULT_OK, result);
                    activity.finish();
                    return;
                } else if (toClipboard) {
                    ClipboardReflection.copyToClipboard(getActivity(), output);
                    AppMsg.makeText(getActivity(), R.string.encrypt_sign_clipboard_successful,
                            AppMsg.STYLE_INFO).show();
                } else {
                    Intent sendIntent = new Intent(Intent.ACTION_SEND);

                    // Type is set to text/plain so that encrypted messages can
                    // be sent with Whatsapp, Hangouts, SMS etc...
                    sendIntent.setType("text/plain");

                    sendIntent.putExtra(Intent.EXTRA_TEXT, output);
                    startActivity(Intent.createChooser(sendIntent, getString(R.string.title_share_with)));
                }
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(saveHandler);
    intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);

    // show progress dialog
    saveHandler.showProgressDialog(getActivity());

    // start service with intent
    getActivity().startService(intent);
}

From source file:org.sufficientlysecure.keychain.ui.EncryptMessageFragment.java

private void encryptStart(final boolean toClipboard) {
    // Send all information needed to service to edit key in other thread
    Intent intent = new Intent(getActivity(), KeychainIntentService.class);

    intent.setAction(KeychainIntentService.ACTION_ENCRYPT_SIGN);

    // fill values for this action
    Bundle data = new Bundle();

    data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_BYTES);

    String message = mMessage.getText().toString();

    if (mEncryptInterface.isModeSymmetric()) {
        Log.d(Constants.TAG, "Symmetric encryption enabled!");
        String passphrase = mEncryptInterface.getPassphrase();
        if (passphrase.length() == 0) {
            passphrase = null;/* www  .  java2  s  .  c  o m*/
        }
        data.putString(KeychainIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase);
    } else {
        data.putLong(KeychainIntentService.ENCRYPT_SIGNATURE_KEY_ID, mEncryptInterface.getSignatureKey());
        data.putLongArray(KeychainIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS,
                mEncryptInterface.getEncryptionKeys());

        boolean signOnly = (mEncryptInterface.getEncryptionKeys() == null
                || mEncryptInterface.getEncryptionKeys().length == 0);
        if (signOnly) {
            message = fixBadCharactersForGmail(message);
        }
    }

    data.putByteArray(KeychainIntentService.ENCRYPT_MESSAGE_BYTES, message.getBytes());

    data.putBoolean(KeychainIntentService.ENCRYPT_USE_ASCII_ARMOR, true);

    int compressionId = Preferences.getPreferences(getActivity()).getDefaultMessageCompression();
    data.putInt(KeychainIntentService.ENCRYPT_COMPRESSION_ID, compressionId);

    intent.putExtra(KeychainIntentService.EXTRA_DATA, data);

    // Message is received after encrypting is done in KeychainIntentService
    KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(),
            getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) {
        public void handleMessage(Message message) {
            // handle messages by standard KeychainIntentServiceHandler first
            super.handleMessage(message);

            if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
                // get returned data bundle
                Bundle data = message.getData();

                String output = new String(data.getByteArray(KeychainIntentService.RESULT_BYTES));
                Log.d(Constants.TAG, "output: " + output);

                if (toClipboard) {
                    ClipboardReflection.copyToClipboard(getActivity(), output);
                    AppMsg.makeText(getActivity(), R.string.encrypt_sign_clipboard_successful,
                            AppMsg.STYLE_INFO).show();
                } else {
                    Intent sendIntent = new Intent(Intent.ACTION_SEND);

                    // Type is set to text/plain so that encrypted messages can
                    // be sent with Whatsapp, Hangouts, SMS etc...
                    sendIntent.setType("text/plain");

                    sendIntent.putExtra(Intent.EXTRA_TEXT, output);
                    startActivity(Intent.createChooser(sendIntent, getString(R.string.title_share_with)));
                }
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(saveHandler);
    intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);

    // show progress dialog
    saveHandler.showProgressDialog(getActivity());

    // start service with intent
    getActivity().startService(intent);
}