From 90a6a1a886c9f7169c9c7917997849f08e002af6 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Wed, 27 Jan 2010 17:59:55 +0100 Subject: [PATCH] Delivery Report working correctly :) --- AndroidManifest.xml | 10 ++- .../openwide/android/DeliveryDbAdapter.java | 12 +-- .../android/EntryContentProvider.java | 78 +++++++++++++++++++ .../openwide/android/GroupEditActivity.java | 1 + src/com/openwide/android/MessageReceiver.java | 16 ++-- src/com/openwide/android/MultiSmsSender.java | 13 +++- .../openwide/android/SelectGroupActivity.java | 1 + 7 files changed, 112 insertions(+), 19 deletions(-) create mode 100644 src/com/openwide/android/EntryContentProvider.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index e330d77..384da03 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,7 +1,7 @@ + package="com.openwide.android" android:versionCode="5" + android:versionName="1.1.0"> @@ -16,10 +16,12 @@ - + + - + + diff --git a/src/com/openwide/android/DeliveryDbAdapter.java b/src/com/openwide/android/DeliveryDbAdapter.java index 718c4c6..53d004b 100644 --- a/src/com/openwide/android/DeliveryDbAdapter.java +++ b/src/com/openwide/android/DeliveryDbAdapter.java @@ -32,10 +32,10 @@ public class DeliveryDbAdapter { * Database creation sql statement */ - private static final String DATABASE_NAME = "data"; - private static final String DATABASE_DELIVERY_ENTRY_TABLE = "delivery_entry"; - private static final String DATABASE_DELIVERY_TABLE = "delivery"; - private static final String DATABASE_DELIVERY_ENTRY_CREATE = "create table " + public static final String DATABASE_NAME = "data"; + public static final String DATABASE_DELIVERY_ENTRY_TABLE = "delivery_entry"; + public static final String DATABASE_DELIVERY_TABLE = "delivery"; + public static final String DATABASE_DELIVERY_ENTRY_CREATE = "create table " + DATABASE_DELIVERY_ENTRY_TABLE + " ("+KEY_DELIVERY_ENTRY_ROWID+" integer primary key autoincrement, " + KEY_DELIVERY_ENTRY_NAME + " text not null," @@ -43,13 +43,13 @@ public class DeliveryDbAdapter { + KEY_DELIVERY_ENTRY_DELIVERED + " integer," + KEY_DELIVERY_ENTRY_DELIVERY_ID + " integer);"; - private static final String DATABASE_DELIVERY_CREATE = "create table " + public static final String DATABASE_DELIVERY_CREATE = "create table " + DATABASE_DELIVERY_TABLE + " (" + KEY_DELIVERY_ROWID + " integer primary key autoincrement, " + KEY_DELIVERY_NAME + " text not null," + KEY_DELIVERY_DATE + " text not null);"; - private static final int DATABASE_VERSION = 2; + public static final int DATABASE_VERSION = 3; private final Context mCtx; diff --git a/src/com/openwide/android/EntryContentProvider.java b/src/com/openwide/android/EntryContentProvider.java new file mode 100644 index 0000000..f909daa --- /dev/null +++ b/src/com/openwide/android/EntryContentProvider.java @@ -0,0 +1,78 @@ +package com.openwide.android; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.database.Cursor; +import android.net.Uri; + +/** + * + * This class is not very usefull... It have been created so we can set Uri for deliveryEntry in the database. + * Thanks to this, sending a SMS (function sendMultipartTextMessage in MultiSmsSender) with a PendingIntent for delivery reports will use different Intent (Intent i = new Intent(message, uri)) + * so PendingIntent.getBroadcast() will return different PendingIntent + * + * @author mathieu + * + */ +public class EntryContentProvider extends ContentProvider{ + public static final String PROVIDER_NAME="com.openwide.android"; + public static final Uri CONTENT_URI = + Uri.parse("content://"+PROVIDER_NAME+ "/entries"); + + + + private static final int ENTRIES = 1; + private static final int ENTRY_ID = 2; + + private static final UriMatcher uriMatcher; + static{ + uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + uriMatcher.addURI(PROVIDER_NAME, "entries", ENTRIES); + uriMatcher.addURI(PROVIDER_NAME, "entries/#", ENTRY_ID); + } + + + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + return 0; + } + + @Override + public String getType(Uri uri) { + switch (uriMatcher.match(uri)){ + case ENTRIES: + return "com.openwide.android.dir/entry "; + case ENTRY_ID: + return "com.openwide.android.item/entry "; + default: + throw new IllegalArgumentException("Unsupported URI: " + uri); + } + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + return null; + } + + @Override + public boolean onCreate() { + + return true; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, + String[] selectionArgs, String sortOrder) { + return null; + } + + @Override + public int update(Uri uri, ContentValues values, String selection, + String[] selectionArgs) { + return 0; + } + + +} diff --git a/src/com/openwide/android/GroupEditActivity.java b/src/com/openwide/android/GroupEditActivity.java index 837b91d..09d25c5 100644 --- a/src/com/openwide/android/GroupEditActivity.java +++ b/src/com/openwide/android/GroupEditActivity.java @@ -46,6 +46,7 @@ public class GroupEditActivity extends ListActivity { String groupName = groupNameCursor.getString(groupNameCursor.getColumnIndex(GroupsDbAdapter.KEY_GROUP_NAME)); mGroupNameText.setText(groupName); Cursor numbers = mDb.fetchPhonesFromGroup(groupId); + startManagingCursor(numbers); numbers.moveToFirst(); int phoneNumIdx = numbers.getColumnIndex(Phones.NUMBER); mSelected = new String[numbers.getCount()]; diff --git a/src/com/openwide/android/MessageReceiver.java b/src/com/openwide/android/MessageReceiver.java index 6af3641..c0ea42c 100644 --- a/src/com/openwide/android/MessageReceiver.java +++ b/src/com/openwide/android/MessageReceiver.java @@ -3,22 +3,28 @@ package com.openwide.android; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.os.Bundle; +import android.net.Uri; import android.util.Log; public class MessageReceiver extends BroadcastReceiver{ public static final String MESSAGE_RECEIVED = "com.openwide.android.SMS_RECEIVED"; public static final String ANDROID_MESSAGE_RECEIVED = "android.provider.Telephony.SMS_RECEIVED"; + public static final String DEBUG_TAG="-------MessageReceiver--------"; @Override public void onReceive(Context context, Intent intent) { - Log.d("------------------", "WORKING :)!!!!"); - if (ANDROID_MESSAGE_RECEIVED.equals(intent.getAction())) { + if (MESSAGE_RECEIVED.equals(intent.getAction())) { + Log.d(DEBUG_TAG, "SMS_RECEIVED"); Long entryId; - Bundle extras = intent.getExtras(); - entryId = extras != null ? extras.getLong(MultiSmsSender.PARAM_ENTRY_ID): null; + //Bundle extras = intent.getExtras(); + //entryId = extras != null ? extras.getLong(MultiSmsSender.PARAM_ENTRY_ID): null; + + Uri entryURI = intent.getData(); + String entryStr = entryURI.getLastPathSegment(); + entryId = Long.parseLong(entryStr); + //byte[] pdu = (byte[]) intent.getByteArrayExtra("pdu"); //SmsMessage message = SmsMessage.createFromPdu(pdu); //int status = message.getStatus(); diff --git a/src/com/openwide/android/MultiSmsSender.java b/src/com/openwide/android/MultiSmsSender.java index 01e55ec..bfa1873 100644 --- a/src/com/openwide/android/MultiSmsSender.java +++ b/src/com/openwide/android/MultiSmsSender.java @@ -12,8 +12,10 @@ import android.app.PendingIntent; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.telephony.PhoneNumberUtils; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -42,6 +44,8 @@ public class MultiSmsSender extends Activity { public static final String PARAM_NUMBERS_LIST = "param number list"; public static final String PARAM_FLUSH = "param flush"; public static final String PARAM_ENTRY_ID = "entry_id"; + + public static final String DEBUG_TAG="MultiSmsSender"; @Override public void onCreate(Bundle savedInstanceState) { @@ -136,12 +140,13 @@ public class MultiSmsSender extends Activity { if (haveDeliveryReports) { long entryId = mDbHelper.createEntry(mDbHelper.nameFromNumber(newN), newN, deliveryId); + Log.d(DEBUG_TAG, "entry is "+entryId); for (int j = 0; j < messageCount; j++) { - - Intent intent = new Intent(MessageReceiver.MESSAGE_RECEIVED, null, this, MessageReceiver.class); - intent.putExtra(PARAM_ENTRY_ID, entryId); + Uri entryURI = Uri.withAppendedPath(EntryContentProvider.CONTENT_URI, ""+entryId); + Intent intent = new Intent(MessageReceiver.MESSAGE_RECEIVED,entryURI, this, MessageReceiver.class); + //intent.putExtra(PARAM_ENTRY_ID, entryId); deliveryIntents.add(PendingIntent.getBroadcast( - this, 0, intent , PendingIntent.FLAG_UPDATE_CURRENT)); + this, 0, intent, 0)); } diff --git a/src/com/openwide/android/SelectGroupActivity.java b/src/com/openwide/android/SelectGroupActivity.java index 4dfd000..a53f639 100644 --- a/src/com/openwide/android/SelectGroupActivity.java +++ b/src/com/openwide/android/SelectGroupActivity.java @@ -79,6 +79,7 @@ public class SelectGroupActivity extends ListActivity{ protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Cursor phonesListCursor = mDbHelper.fetchPhonesFromGroup(id); + startManagingCursor(phonesListCursor); int phoneNumberIdx = phonesListCursor.getColumnIndex(Phones.NUMBER); String[] res = new String[phonesListCursor.getCount()]; phonesListCursor.moveToFirst();