A third source next to voip.ms and Google Voice, while bubble is Android's default SMS app (Settings → SIM card asks for the role). SMS and MMS in and out, group chats as MMS, the phone's existing texts imported, and Android's message store kept as the record so another app still agrees. - Sim: role check, sending (SmsManager, waits for the radio), receiving, chunked import from content://sms and content://mms - Pdu: MMS wire format (notification-ind, retrieve-conf, send-req, ack) - SmsReceiver, MmsReceiver, MmsDownloaded, MmsFiles, RespondService, SendToActivity: what Android requires of a default SMS app - The import no longer shares a lock with Config.get, which froze the screens on the first copy of a long history
64 lines
2.5 KiB
Java
64 lines
2.5 KiB
Java
package me.teafry.voipmessages;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* sms:/smsto:/mms:/mmsto: links from other apps ("Message" on a contact, a
|
|
* number on a web page): opens that chat, with any text they passed as the draft.
|
|
*/
|
|
public final class SendToActivity extends Activity {
|
|
/** The conversation key for an sms: link's recipients ("" if none). */
|
|
static String contact(Uri uri) {
|
|
String ssp = uri.getSchemeSpecificPart();
|
|
if (ssp == null) return "";
|
|
int q = ssp.indexOf('?');
|
|
if (q >= 0) ssp = ssp.substring(0, q);
|
|
List<String> nums = new ArrayList<>();
|
|
for (String s : ssp.split("[,;]")) {
|
|
String n = Sim.contactFor(s);
|
|
if (!n.isEmpty()) nums.add(n);
|
|
}
|
|
if (nums.isEmpty()) return "";
|
|
return nums.size() == 1 ? nums.get(0) : Phone.groupKey(nums);
|
|
}
|
|
|
|
@Override
|
|
protected void onCreate(Bundle b) {
|
|
super.onCreate(b);
|
|
Intent in = getIntent();
|
|
Uri data = in.getData();
|
|
String contact = data == null ? "" : contact(data);
|
|
String body = in.getStringExtra("sms_body");
|
|
if (body == null) body = in.getStringExtra(Intent.EXTRA_TEXT);
|
|
if (body == null && data != null && data.isHierarchical()) body = data.getQueryParameter("body");
|
|
if (body == null && data != null) {
|
|
String ssp = data.getSchemeSpecificPart();
|
|
int q = ssp == null ? -1 : ssp.indexOf("body=");
|
|
if (q >= 0) body = Uri.decode(ssp.substring(q + 5));
|
|
}
|
|
if (contact.isEmpty()) {
|
|
startActivity(new Intent(this, NewChatActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
|
finish();
|
|
return;
|
|
}
|
|
if (body != null && !body.trim().isEmpty())
|
|
getSharedPreferences("drafts", MODE_PRIVATE).edit().putString(contact, body).apply();
|
|
startActivity(ChatActivity.intent(this, didFor(contact), contact));
|
|
finish();
|
|
}
|
|
|
|
/** An existing chat with them from any number; otherwise the SIM. */
|
|
private String didFor(String contact) {
|
|
for (Store.Conv c : Store.get(this).conversations(null)) if (c.contact.equals(contact)) return c.did;
|
|
Config cfg = Config.get(this);
|
|
for (Config.Did d : cfg.dids) if (d.sim) return d.did;
|
|
return cfg.defaultDid != null ? cfg.defaultDid : Sim.DID;
|
|
}
|
|
}
|