Delivery intents *Should* be working but... ?? Implements a mySMSManger to use cupcake or newer version of SMSManager

This commit is contained in:
Mathieu Maret 2010-01-26 15:46:26 +01:00
parent 5f29b32554
commit 6c373b51e5
9 changed files with 131 additions and 11 deletions

View File

@ -14,7 +14,11 @@
<activity android:name="GroupEditActivity"></activity>
<activity android:name="SelectDeliveryActivity"></activity>
<activity android:name="ListEntryActivity"></activity>
<receiver android:name="MessageReceiver" android:exported="false" ></receiver>
<receiver android:name="MessageReceiver">
<intent-filter>
<action android:name="com.openwide.android.mutliSmsSend.message_received"/>
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4" />
<supports-screens android:smallScreens="true"

View File

@ -17,6 +17,7 @@
<string name="remove">Supprimer</string>
<string name="add_group">Ajouter un groupe</string>
<string name="delivery">Accusé de récéption</string>
<string name="nodelivery">Aucun accusé de récéption</string>
<string name="enabledelivery">Accusé de récéption</string>
<string name="create_group">Créer un group</string>
<string name="remove_group">Supprimer ce groupe</string>

View File

@ -6,6 +6,7 @@ import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.provider.Contacts.Phones;
import android.util.Log;
@ -236,13 +237,12 @@ public class DeliveryDbAdapter {
public String nameFromNumber(String number) {
//TODO
//Cursor c1 = mCtx.getContentResolver().query(Phones.CONTENT_URI, new String[] { Phones.NUMBER }, null, null, null);
Cursor c = mCtx.getContentResolver().query(Phones.CONTENT_URI, new String[] { Phones.NAME }, Phones.NUMBER +"="+number, null, null);
Uri contactUri = Uri.withAppendedPath(Phones.CONTENT_FILTER_URL, Uri.encode(number));
Cursor c = mCtx.getContentResolver().query(contactUri, new String[] { Phones.DISPLAY_NAME }, null, null, null);
if(c != null) {
c.moveToFirst();
if(c.isFirst()) {
return c.getString(c.getColumnIndex(Phones.NAME));
return c.getString(c.getColumnIndex(Phones.DISPLAY_NAME));
}else {
return "";
}

View File

@ -4,6 +4,8 @@ import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
@ -12,6 +14,7 @@ import android.widget.SimpleCursorAdapter;
public class ListEntryActivity extends ListActivity {
DeliveryDbAdapter mDbHelper;
Long mDeliveryId;
public static final int REFRESH_ID = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -53,6 +56,23 @@ public class ListEntryActivity extends ListActivity {
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, REFRESH_ID,0, R.string.refresh);
return true;
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case REFRESH_ID:
fillData();
return true;
}
return super.onContextItemSelected(item);
}
private class EntryCursorAdapter extends SimpleCursorAdapter{
Cursor c;
int deliveredIdx;
@ -83,5 +103,7 @@ public class ListEntryActivity extends ListActivity {
return v;
}
}
}

View File

@ -4,16 +4,21 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
public class MessageReceiver extends BroadcastReceiver{
public static final String MESSAGE_RECEIVED = "com.openwide.android.mutliSmsSend.message_received";
@Override
public void onReceive(Context context, Intent intent) {
Log.d("------------------", "WORKING :)!!!!");
if (MESSAGE_RECEIVED.equals(intent.getAction())) {
Long entryId;
Bundle extras = intent.getExtras();
entryId = extras != null ? extras.getLong(MultiSmsSender.PARAM_ENTRY_ID): null;
//byte[] pdu = (byte[]) intent.getByteArrayExtra("pdu");
//SmsMessage message = SmsMessage.createFromPdu(pdu);
//int status = message.getStatus();
DeliveryDbAdapter mDbHelper = new DeliveryDbAdapter(context);
mDbHelper.open();
mDbHelper.setEntryDelivered(entryId);
@ -21,9 +26,6 @@ public class MessageReceiver extends BroadcastReceiver{
}
}
}

View File

@ -10,12 +10,10 @@ import android.app.AlertDialog;
import android.app.Dialog;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.PhoneNumberUtils;
import android.telephony.gsm.SmsManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -89,7 +87,7 @@ public class MultiSmsSender extends Activity {
}
public void sendMessage() {
SmsManager manager = SmsManager.getDefault();
MySMSManager manager = MySMSManager.getInstance();
String message = mEditor.getText().toString();
String[] numbers = mContacts.getText().toString().split(",");
HashSet<String> allreadySend = new HashSet<String>();

View File

@ -0,0 +1,34 @@
package com.openwide.android;
import java.util.ArrayList;
import android.app.PendingIntent;
import android.os.Build;
public abstract class MySMSManager {
private static MySMSManager sInstance;
public static MySMSManager getInstance() {
if(sInstance == null) {
String className;
int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
if (sdkVersion < Build.VERSION_CODES.DONUT) {
className = "com.openwide.android.MySMSManagerCupcake";
} else {
className = "com.openwide.android.MySMSManagerOther";
}
try {
Class<? extends MySMSManager> clazz =
Class.forName(className).asSubclass(MySMSManager.class);
sInstance = clazz.newInstance();
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
return sInstance;
}
public abstract ArrayList<String> divideMessage(String text);
public abstract void sendMultipartTextMessage(String destinationAddress, String scAddress, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents );
}

View File

@ -0,0 +1,29 @@
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);
}
}

View File

@ -0,0 +1,30 @@
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);
}
}