Code example for Intent

Methods: hasExtra

  // Handles send intents from multitude of Android applications 
  private boolean encodeContentsFromShareIntent(Intent intent) {
    // Check if this is a plain text encoding, or contact 
    if (intent.hasExtra(Intent.EXTRA_TEXT)) {
      return encodeContentsFromShareIntentPlainText(intent);
    // Attempt default sharing. 
    return encodeContentsFromShareIntentDefault(intent);
  private boolean encodeContentsFromShareIntentPlainText(Intent intent) {
    // Notice: Google Maps shares both URL and details in one text, bummer! 
    contents = intent.getStringExtra(Intent.EXTRA_TEXT);
    // We only support non-empty and non-blank texts. 
    // Trim text to avoid URL breaking. 
    if (contents == null) {
      return false; 
    contents = contents.trim();