Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dcf9cfd7 authored by Moez Bhatti's avatar Moez Bhatti
Browse files

Implemented SMSSendService

parent bcc9777b
Loading
Loading
Loading
Loading
+42 −5
Original line number Diff line number Diff line
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);
            }
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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'
    }
}