From dcf9cfd74d8c9a309dd9791128e569a1c3dd3fa9 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Tue, 5 Jul 2016 00:44:32 -0400 Subject: [PATCH] Implemented SMSSendService --- .../QKSMS/service/HeadlessSmsSendService.java | 47 +++++++++++++++++-- build.gradle | 2 +- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/service/HeadlessSmsSendService.java b/QKSMS/src/main/java/com/moez/QKSMS/service/HeadlessSmsSendService.java index 2bd6eafc..213ce11d 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/service/HeadlessSmsSendService.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/service/HeadlessSmsSendService.java @@ -1,12 +1,49 @@ package com.moez.QKSMS.service; -import android.app.Service; +import android.app.IntentService; import android.content.Intent; -import android.os.IBinder; +import android.net.Uri; +import android.os.Bundle; +import android.telephony.TelephonyManager; +import android.text.TextUtils; +import com.moez.QKSMS.mmssms.Message; +import com.moez.QKSMS.mmssms.Transaction; +import com.moez.QKSMS.transaction.NotificationManager; +import com.moez.QKSMS.transaction.SmsHelper; + +import static com.moez.QKSMS.data.Conversation.getRecipients; + +public class HeadlessSmsSendService extends IntentService { + private static final String TAG = "HeadlessSmsSendService"; + + public HeadlessSmsSendService() { + super(TAG); + } -public class HeadlessSmsSendService extends Service { @Override - public IBinder onBind(Intent intent) { - return null; + protected void onHandleIntent(Intent intent) { + String action = intent.getAction(); + if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(action)) { + return; + } + + Bundle extras = intent.getExtras(); + if (extras != null) { + String body = extras.getString(Intent.EXTRA_TEXT); + Uri intentUri = intent.getData(); + String recipients = getRecipients(intentUri); + + if (!TextUtils.isEmpty(recipients) && !TextUtils.isEmpty(body)) { + String[] destinations = TextUtils.split(recipients, ";"); + + Transaction sendTransaction = new Transaction(this, SmsHelper.getSendSettings(this)); + + Message message = new Message(body, destinations); + message.setType(Message.TYPE_SMSMMS); + + sendTransaction.sendNewMessage(message, Transaction.NO_THREAD_ID); + NotificationManager.update(this); + } + } } } diff --git a/build.gradle b/build.gradle index 29049ffa..0edb821f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,6 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.0-alpha3' + classpath 'com.android.tools.build:gradle:2.1.2' } }