session-android/src/org/thoughtcrime/securesms/SmsSendtoActivity.java
Rhodey Orbits 8f002bd68d fix handling of sms:, smsto:, mms:, mmsto: URIs
1) add VIEW action and BROWSABLE category to SmsSendtoActivity intent filter
2) created class Rfc5724Uri for processing RFC5724 SMS URIs
3) added a set of tests for new Rfc5724Uri class
4) updated SmsSendtoActivity to use Rfc5742Uri for processing VIEW intents

Fixes #2578
Closes #3030

// FREEBIE
2015-04-30 11:54:38 -07:00

60 lines
2.1 KiB
Java

package org.thoughtcrime.securesms;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.util.Rfc5724Uri;
import java.net.URISyntaxException;
public class SmsSendtoActivity extends Activity {
private static final String TAG = SmsSendtoActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
startActivity(getNextIntent(getIntent()));
finish();
super.onCreate(savedInstanceState);
}
private Intent getNextIntent(Intent original) {
String body = "";
String data = "";
if (original.getAction().equals(Intent.ACTION_SENDTO)) {
body = original.getStringExtra("sms_body");
data = original.getData().getSchemeSpecificPart();
} else {
try {
Rfc5724Uri smsUri = new Rfc5724Uri(original.getData().toString());
body = smsUri.getQueryParams().get("body");
data = smsUri.getPath();
} catch (URISyntaxException e) {
Log.w(TAG, "unable to parse RFC5724 URI from intent", e);
}
}
Recipients recipients = RecipientFactory.getRecipientsFromString(this, data, false);
long threadId = DatabaseFactory.getThreadDatabase(this).getThreadIdIfExistsFor(recipients);
final Intent nextIntent;
if (recipients == null || recipients.isEmpty()) {
nextIntent = new Intent(this, NewConversationActivity.class);
nextIntent.putExtra(ConversationActivity.DRAFT_TEXT_EXTRA, body);
Toast.makeText(this, R.string.ConversationActivity_specify_recipient, Toast.LENGTH_LONG).show();
} else {
nextIntent = new Intent(this, ConversationActivity.class);
nextIntent.putExtra(ConversationActivity.DRAFT_TEXT_EXTRA, body);
nextIntent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
nextIntent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
}
return nextIntent;
}
}