8
8
9
9
package com .android .shellms ;
10
10
11
+ import java .util .ArrayList ;
12
+
11
13
import android .net .Uri ;
12
14
import android .os .Bundle ;
15
+ import android .app .PendingIntent ;
13
16
import android .app .Service ;
14
17
import android .telephony .PhoneNumberUtils ;
15
18
import android .telephony .SmsManager ;
@@ -106,9 +109,9 @@ public int onStartCommand(Intent intent, int flags, int startId) {
106
109
sendsms (contact , msg , !SECRET );
107
110
Log .i (TAG , "Sent SMS to contact: " + contact );
108
111
} else {
109
- Log .e (TAG , "NO MESSAGE WILL BE SENT IN DEBUG MODE" );
110
- Log .e (TAG , "Contact: " + contact );
111
- Log .e (TAG , "Message: " + msg );
112
+ Log .d (TAG , "NO MESSAGE WILL BE SENT IN DEBUG MODE" );
113
+ Log .d (TAG , "Contact: " + contact );
114
+ Log .d (TAG , "Message: " + msg );
112
115
}
113
116
} else {
114
117
Log .e (TAG , "Unknown Error occoured with contact: " + contact );
@@ -202,16 +205,34 @@ private String getNumberfromContact(String contact, Boolean debugging) {
202
205
}
203
206
}
204
207
205
-
206
208
// This function sends the sms with the SMSManager
207
209
private void sendsms (String phoneNumber , String message , Boolean AddtoSent ) {
208
- SmsManager sms = SmsManager .getDefault ();
209
- sms .sendTextMessage (phoneNumber , null , message , null , null );
210
- if (AddtoSent ) {
211
- addMessageToSent (phoneNumber , message );
212
- }
213
- }
214
-
210
+ String SENT = "SMS_SENT" ;
211
+ String DELIVERED = "SMS_DELIVERED" ;
212
+
213
+ ArrayList <PendingIntent > sentPendingIntents = new ArrayList <PendingIntent >();
214
+ ArrayList <PendingIntent > deliveredPendingIntents = new ArrayList <PendingIntent >();
215
+
216
+ PendingIntent sentPI = PendingIntent .getBroadcast (this , 0 , new Intent (SENT ), 0 );
217
+ PendingIntent deliveredPI = PendingIntent .getBroadcast (this , 0 , new Intent (DELIVERED ), 0 );
218
+
219
+ try {
220
+ SmsManager sms = SmsManager .getDefault ();
221
+ ArrayList <String > msgparts = sms .divideMessage (message );
222
+ for (int i = 0 ; i < msgparts .size (); i ++) {
223
+ sentPendingIntents .add (i , sentPI );
224
+ deliveredPendingIntents .add (i , deliveredPI );
225
+ }
226
+ sms .sendMultipartTextMessage (phoneNumber , null , msgparts , sentPendingIntents , deliveredPendingIntents );
227
+ if (AddtoSent ) {
228
+ addMessageToSent (phoneNumber , message );
229
+ }
230
+ } catch (Exception e ) {
231
+ e .printStackTrace ();
232
+ Log .e (TAG , "undefined Error: SMS sending failed ... please REPORT to ISSUE Tracker" );
233
+ }
234
+ }
235
+
215
236
// This function add's the sent sms to the SMS sent folder
216
237
private void addMessageToSent (String phoneNumber , String message ) {
217
238
ContentValues sentSms = new ContentValues ();
@@ -220,8 +241,8 @@ private void addMessageToSent(String phoneNumber, String message) {
220
241
221
242
ContentResolver contentResolver = getContentResolver ();
222
243
contentResolver .insert (SENT_MSGS_CONTET_PROVIDER , sentSms );
223
- }
224
-
244
+ }
245
+
225
246
@ Override
226
247
public IBinder onBind (Intent intent ) {
227
248
// TODO Auto-generated method stub
0 commit comments