Delivery Report working correctly :)

This commit is contained in:
Mathieu Maret 2010-01-27 17:59:55 +01:00
parent e72d637222
commit 90a6a1a886
7 changed files with 112 additions and 19 deletions

View File

@ -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="4" package="com.openwide.android" android:versionCode="5"
android:versionName="1.0.2"> android:versionName="1.1.0">
<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>
@ -16,9 +16,11 @@
<activity android:name="ListEntryActivity"></activity> <activity android:name="ListEntryActivity"></activity>
<receiver android:name=".MessageReceiver" android:enabled="true" > <receiver android:name=".MessageReceiver" android:enabled="true" >
<intent-filter> <intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/> <action android:name="com.openwide.android.SMS_RECEIVED"/>
<data android:mimeType="com.openwide.android.item/entry"/>
</intent-filter> </intent-filter>
</receiver> </receiver>
<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" android:targetSdkVersion="4" />
<supports-screens android:smallScreens="true" <supports-screens android:smallScreens="true"

View File

@ -32,10 +32,10 @@ public class DeliveryDbAdapter {
* Database creation sql statement * Database creation sql statement
*/ */
private static final String DATABASE_NAME = "data"; public static final String DATABASE_NAME = "data";
private static final String DATABASE_DELIVERY_ENTRY_TABLE = "delivery_entry"; public static final String DATABASE_DELIVERY_ENTRY_TABLE = "delivery_entry";
private static final String DATABASE_DELIVERY_TABLE = "delivery"; public static final String DATABASE_DELIVERY_TABLE = "delivery";
private static final String DATABASE_DELIVERY_ENTRY_CREATE = "create table " public static final String DATABASE_DELIVERY_ENTRY_CREATE = "create table "
+ DATABASE_DELIVERY_ENTRY_TABLE + DATABASE_DELIVERY_ENTRY_TABLE
+ " ("+KEY_DELIVERY_ENTRY_ROWID+" integer primary key autoincrement, " + " ("+KEY_DELIVERY_ENTRY_ROWID+" integer primary key autoincrement, "
+ KEY_DELIVERY_ENTRY_NAME + " text not null," + KEY_DELIVERY_ENTRY_NAME + " text not null,"
@ -43,13 +43,13 @@ public class DeliveryDbAdapter {
+ KEY_DELIVERY_ENTRY_DELIVERED + " integer," + KEY_DELIVERY_ENTRY_DELIVERED + " integer,"
+ KEY_DELIVERY_ENTRY_DELIVERY_ID + " 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 + DATABASE_DELIVERY_TABLE
+ " (" + KEY_DELIVERY_ROWID + " integer primary key autoincrement, " + " (" + KEY_DELIVERY_ROWID + " integer primary key autoincrement, "
+ KEY_DELIVERY_NAME + " text not null," + KEY_DELIVERY_NAME + " text not null,"
+ KEY_DELIVERY_DATE + " 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; private final Context mCtx;

View File

@ -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;
}
}

View File

@ -46,6 +46,7 @@ public class GroupEditActivity extends ListActivity {
String groupName = groupNameCursor.getString(groupNameCursor.getColumnIndex(GroupsDbAdapter.KEY_GROUP_NAME)); String groupName = groupNameCursor.getString(groupNameCursor.getColumnIndex(GroupsDbAdapter.KEY_GROUP_NAME));
mGroupNameText.setText(groupName); mGroupNameText.setText(groupName);
Cursor numbers = mDb.fetchPhonesFromGroup(groupId); Cursor numbers = mDb.fetchPhonesFromGroup(groupId);
startManagingCursor(numbers);
numbers.moveToFirst(); numbers.moveToFirst();
int phoneNumIdx = numbers.getColumnIndex(Phones.NUMBER); int phoneNumIdx = numbers.getColumnIndex(Phones.NUMBER);
mSelected = new String[numbers.getCount()]; mSelected = new String[numbers.getCount()];

View File

@ -3,22 +3,28 @@ package com.openwide.android;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.net.Uri;
import android.util.Log; import android.util.Log;
public class MessageReceiver extends BroadcastReceiver{ public class MessageReceiver extends BroadcastReceiver{
public static final String MESSAGE_RECEIVED = "com.openwide.android.SMS_RECEIVED"; 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 ANDROID_MESSAGE_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
public static final String DEBUG_TAG="-------MessageReceiver--------";
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.d("------------------", "WORKING :)!!!!"); if (MESSAGE_RECEIVED.equals(intent.getAction())) {
if (ANDROID_MESSAGE_RECEIVED.equals(intent.getAction())) { Log.d(DEBUG_TAG, "SMS_RECEIVED");
Long entryId; Long entryId;
Bundle extras = intent.getExtras(); //Bundle extras = intent.getExtras();
entryId = extras != null ? extras.getLong(MultiSmsSender.PARAM_ENTRY_ID): null; //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"); //byte[] pdu = (byte[]) intent.getByteArrayExtra("pdu");
//SmsMessage message = SmsMessage.createFromPdu(pdu); //SmsMessage message = SmsMessage.createFromPdu(pdu);
//int status = message.getStatus(); //int status = message.getStatus();

View File

@ -12,8 +12,10 @@ import android.app.PendingIntent;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.telephony.PhoneNumberUtils; import android.telephony.PhoneNumberUtils;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -43,6 +45,8 @@ public class MultiSmsSender extends Activity {
public static final String PARAM_FLUSH = "param flush"; public static final String PARAM_FLUSH = "param flush";
public static final String PARAM_ENTRY_ID = "entry_id"; public static final String PARAM_ENTRY_ID = "entry_id";
public static final String DEBUG_TAG="MultiSmsSender";
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -136,12 +140,13 @@ public class MultiSmsSender extends Activity {
if (haveDeliveryReports) { if (haveDeliveryReports) {
long entryId = mDbHelper.createEntry(mDbHelper.nameFromNumber(newN), newN, deliveryId); long entryId = mDbHelper.createEntry(mDbHelper.nameFromNumber(newN), newN, deliveryId);
Log.d(DEBUG_TAG, "entry is "+entryId);
for (int j = 0; j < messageCount; j++) { for (int j = 0; j < messageCount; j++) {
Uri entryURI = Uri.withAppendedPath(EntryContentProvider.CONTENT_URI, ""+entryId);
Intent intent = new Intent(MessageReceiver.MESSAGE_RECEIVED, null, this, MessageReceiver.class); Intent intent = new Intent(MessageReceiver.MESSAGE_RECEIVED,entryURI, this, MessageReceiver.class);
intent.putExtra(PARAM_ENTRY_ID, entryId); //intent.putExtra(PARAM_ENTRY_ID, entryId);
deliveryIntents.add(PendingIntent.getBroadcast( deliveryIntents.add(PendingIntent.getBroadcast(
this, 0, intent , PendingIntent.FLAG_UPDATE_CURRENT)); this, 0, intent, 0));
} }

View File

@ -79,6 +79,7 @@ public class SelectGroupActivity extends ListActivity{
protected void onListItemClick(ListView l, View v, int position, long id) { protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id); super.onListItemClick(l, v, position, id);
Cursor phonesListCursor = mDbHelper.fetchPhonesFromGroup(id); Cursor phonesListCursor = mDbHelper.fetchPhonesFromGroup(id);
startManagingCursor(phonesListCursor);
int phoneNumberIdx = phonesListCursor.getColumnIndex(Phones.NUMBER); int phoneNumberIdx = phonesListCursor.getColumnIndex(Phones.NUMBER);
String[] res = new String[phonesListCursor.getCount()]; String[] res = new String[phonesListCursor.getCount()];
phonesListCursor.moveToFirst(); phonesListCursor.moveToFirst();