Fix SMS sending with different API version
This commit is contained in:
parent
bdcd99ce2b
commit
23a7d0ea09
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.openwide.android" android:versionCode="7"
|
package="com.openwide.android" android:versionCode="8"
|
||||||
android:versionName="1.1.3">
|
android:versionName="1.1.4">
|
||||||
<application android:label="@string/app_name" android:icon="@drawable/multisms">
|
<application android:label="@string/app_name" android:icon="@drawable/multisms">
|
||||||
<activity android:name=".MultiSmsSender" android:label="@string/app_name">
|
<activity android:name=".MultiSmsSender" android:label="@string/app_name">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@ -22,10 +22,7 @@
|
|||||||
</receiver>
|
</receiver>
|
||||||
<provider android:authorities="com.openwide.android" android:name="EntryContentProvider"></provider>
|
<provider android:authorities="com.openwide.android" android:name="EntryContentProvider"></provider>
|
||||||
</application>
|
</application>
|
||||||
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4" />
|
<uses-sdk android:minSdkVersion="3" />
|
||||||
<supports-screens android:smallScreens="true"
|
|
||||||
android:anyDensity="true" />
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
|
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
|
||||||
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
|
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
|
||||||
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
|
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
|
||||||
|
@ -23,7 +23,6 @@ import android.database.SQLException;
|
|||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.provider.Contacts.Phones;
|
import android.provider.Contacts.Phones;
|
||||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,7 +91,7 @@ public class MultiSmsSender extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage() {
|
public void sendMessage() {
|
||||||
MySMSManager manager = MySMSManager.getInstance();
|
MySMSManager manager = new MySMSManager();
|
||||||
String message = mEditor.getText().toString();
|
String message = mEditor.getText().toString();
|
||||||
|
|
||||||
if("".equals(message)) {
|
if("".equals(message)) {
|
||||||
|
@ -1,34 +1,77 @@
|
|||||||
package com.openwide.android;
|
package com.openwide.android;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public abstract class MySMSManager {
|
public class MySMSManager {
|
||||||
private static MySMSManager sInstance;
|
private static Object manager;
|
||||||
|
private static Method getDefault;
|
||||||
|
private static Method divide;
|
||||||
|
private static Method sendMutlipart;
|
||||||
|
|
||||||
public static MySMSManager getInstance() {
|
public MySMSManager() {
|
||||||
if(sInstance == null) {
|
if(manager == null) {
|
||||||
String className;
|
String className;
|
||||||
int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
|
int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
|
||||||
if (sdkVersion < Build.VERSION_CODES.DONUT) {
|
if (sdkVersion <= 3) { //CUPCAKE
|
||||||
className = "com.openwide.android.MySMSManagerCupcake";
|
Log.d("MultiSMSSender", "Cupcake version");
|
||||||
|
className = "android.telephony.gsm.SmsManager";
|
||||||
} else {
|
} else {
|
||||||
className = "com.openwide.android.MySMSManagerOther";
|
Log.d("MultiSMSSender", "version > Cupcake");
|
||||||
|
className = "android.telephony.SmsManager";
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Class<? extends MySMSManager> clazz =
|
Class clazz =
|
||||||
Class.forName(className).asSubclass(MySMSManager.class);
|
Class.forName(className);
|
||||||
sInstance = clazz.newInstance();
|
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);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalStateException(e);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sInstance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract ArrayList<String> divideMessage(String text);
|
public ArrayList<String> divideMessage(String text){
|
||||||
public abstract void sendMultipartTextMessage(String destinationAddress, String scAddress, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents );
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
package com.openwide.android;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.telephony.gsm.SmsManager;
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class MySMSManagerCupcake extends MySMSManager {
|
|
||||||
|
|
||||||
SmsManager mManager;
|
|
||||||
public MySMSManagerCupcake() {
|
|
||||||
mManager = SmsManager.getDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList<String> divideMessage(String text) {
|
|
||||||
|
|
||||||
return mManager.divideMessage(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMultipartTextMessage(String destinationAddress, String scAddress, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents ) {
|
|
||||||
mManager.sendMultipartTextMessage(destinationAddress, scAddress, parts, sentIntents, deliveryIntents);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package com.openwide.android;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.telephony.SmsManager;
|
|
||||||
|
|
||||||
public class MySMSManagerOther extends MySMSManager {
|
|
||||||
|
|
||||||
SmsManager mManager;
|
|
||||||
public MySMSManagerOther() {
|
|
||||||
mManager = SmsManager.getDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList<String> divideMessage(String text) {
|
|
||||||
|
|
||||||
return mManager.divideMessage(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMultipartTextMessage(String destinationAddress,
|
|
||||||
String scAddress, ArrayList<String> parts,
|
|
||||||
ArrayList<PendingIntent> sentIntents,
|
|
||||||
ArrayList<PendingIntent> deliveryIntents) {
|
|
||||||
mManager.sendMultipartTextMessage(destinationAddress, scAddress, parts, sentIntents, deliveryIntents);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user