2

I am trying to send text using an intent. I thought it was straight-forward:

public Intent getIntent() {
    final Intent intent = new Intent();
    intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
    intent.setAction(Intent.ACTION_SEND);
    intent.setType("text/plain"); 
    intent.putExtra(Intent.EXTRA_TEXT, getText());
    return intent;
}

private String getText(){
    // the emoji can be one of many. I removed all that for brevity 
    final int unicode = 0x1F3C5;
    final String emoji = String.valueOf(Character.toChars(unicode));
    // final String emoji = "\n1F3C5"; //didn't work either
    // I also tried using HTML here but I think I have some wires crossed, so I am not ruling that out yet
    return textPartOne + " " + emoji + " " + textPartTwo;
}

As you can see, the EXTRA_TEXT has a special character in it (an emoji). When the text sends from device A the emoji appears like I expect in the message. But on device B (the receiver) the text shows some madness (usually in two different messages):

@.£¡ù¿ ¡ ¡ | | < | | | \ < | [ ¡ { ¡ [ ¡

@H£(ù@æ@a@¤¥¡

¡9@ü@Hù@Θ@=@ø¥p

¡6@Ö@Δì¿ ¡ |

It doesn't matter if I send the message from device A to device B or B to A. I get the same results either way, so I believe it isn't an issue with the emoji not being supported.

Now, if I remove all but the emoji code:

Xäx&

If I remove the emoji code altogether it works like a charm.

But the client has gotta have those emojis...


Some other things that may be of note:

  • I am using this to manage what intents I am presenting to the user. They could pick MMS, email, Twitter, Facebook or whatever really. I need to support all of these

  • I am getting the special characters from Emojipedia

  • I am not displaying the emojis anywhere in the app. They will be shown in Text message, Email, or Facebook/Twitter feed.

  • There is already an iOS variant of this app who is successfully doing this.

I have tried nearly a dozen different ways with no avail. Is there anyone that may have some insight on how to properly send special characters?


Edit:

As you can see, I am sending the emoji I desire. But the result is far from what I expect. This is a screenshot of an emulator sending a text to itself. enter image description here

Here are some of the ways I have tried

    String attempt1 = "--";
    try {
        attempt1 = Html.fromHtml(new String("&#x1F3C5".getBytes("UTF-8"))).toString();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    final int codePoint = 0x26F7;
    final String attempt2 = new String(new int[]{codePoint}, 0, 1);

    final String attempt3 = new String(Character.toChars(codePoint));
    final String attempt4 = "\u26F7";

All result in:

&n

If I add text to these:

final String attempt4 = "COME ON: \u26F7";

I get this:

@Σ£(ù@æ@s@@£ Å¡7@X£¿ù¿

Which makes total sense he said sarcastically

Chad Bingham
  • 32,650
  • 19
  • 86
  • 115

1 Answers1

-1

You can use intents, which are messages sent between activities. In a intent you can put all sort of data, String, int, etc.

In your case, in activity2, before going to activity1, you will store a String message this way :

Intent intent = new Intent(activity2.this, activity1.class);
intent.putExtra("message", getText());
startActivity(intent);

In activity1, in onCreate(), you can get the String message by retrieving a Bundle (which contains all the messages sent by the calling activity) and call getString() on it :

Bundle bundle = getIntent().getExtras();
String message = bundle.getString("message");

Then you can set the text in the TextView:

TextView txtView = (TextView) findViewById(R.id.your_resource_textview);    
txtView.setText(message);

Hope this helps !