2010-01-26 15:46:26 +01:00
|
|
|
package com.openwide.android;
|
|
|
|
|
2010-05-06 14:05:03 +02:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
2010-01-26 15:46:26 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.os.Build;
|
2010-05-06 14:05:03 +02:00
|
|
|
import android.util.Log;
|
2010-01-26 15:46:26 +01:00
|
|
|
|
2010-05-06 14:05:03 +02:00
|
|
|
public class MySMSManager {
|
|
|
|
private static Object manager;
|
|
|
|
private static Method getDefault;
|
|
|
|
private static Method divide;
|
|
|
|
private static Method sendMutlipart;
|
2010-01-26 15:46:26 +01:00
|
|
|
|
2010-05-06 14:05:03 +02:00
|
|
|
public MySMSManager() {
|
|
|
|
if(manager == null) {
|
2010-01-26 15:46:26 +01:00
|
|
|
String className;
|
|
|
|
int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
|
2010-05-06 14:05:03 +02:00
|
|
|
if (sdkVersion <= 3) { //CUPCAKE
|
|
|
|
Log.d("MultiSMSSender", "Cupcake version");
|
|
|
|
className = "android.telephony.gsm.SmsManager";
|
2010-01-26 15:46:26 +01:00
|
|
|
} else {
|
2010-05-06 14:05:03 +02:00
|
|
|
Log.d("MultiSMSSender", "version > Cupcake");
|
|
|
|
className = "android.telephony.SmsManager";
|
2010-01-26 15:46:26 +01:00
|
|
|
}
|
|
|
|
try {
|
2010-05-06 14:05:03 +02:00
|
|
|
Class clazz =
|
|
|
|
Class.forName(className);
|
|
|
|
Object[] paramInvoke = new Object[0];
|
|
|
|
Class[] signGetDefault = new Class[]{};
|
|
|
|
Class<String>[] signDivide = new Class[] {String.class};
|
|
|
|
Class[] signSend = new Class[] {String.class, String.class, ArrayList.class, ArrayList.class, ArrayList.class};
|
|
|
|
getDefault = clazz.getMethod("getDefault", signGetDefault);
|
|
|
|
divide = clazz.getMethod("divideMessage", signDivide);
|
|
|
|
sendMutlipart = clazz.getMethod("sendMultipartTextMessage", signSend);
|
|
|
|
manager = getDefault.invoke(null, paramInvoke);
|
2010-01-26 15:46:26 +01:00
|
|
|
} catch (Exception e) {
|
2010-05-06 14:05:03 +02:00
|
|
|
e.printStackTrace();
|
2010-01-26 15:46:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-06 14:05:03 +02:00
|
|
|
public ArrayList<String> divideMessage(String text){
|
|
|
|
Object[] param = new Object[1];
|
|
|
|
param[0] = text;
|
|
|
|
try {
|
|
|
|
return (ArrayList<String>)divide.invoke(manager, param);
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
public void sendMultipartTextMessage(String destinationAddress, String scAddress, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents ) {
|
|
|
|
Object[] param = new Object[5];
|
|
|
|
param[0] = destinationAddress;
|
|
|
|
param[1] = scAddress;
|
|
|
|
param[2] = parts;
|
|
|
|
param[3] = sentIntents;
|
|
|
|
param[4] = deliveryIntents;
|
|
|
|
try {
|
|
|
|
sendMutlipart.invoke(manager, param);
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2010-01-26 15:46:26 +01:00
|
|
|
|
|
|
|
}
|