Permalink
Browse files

Easier name of Intent for DT and Notification starts an activity to r…

…ead SMS
  • Loading branch information...
1 parent 127313e commit 7e47cfc7e28c8f236d9abbffbe925defc6e8dd5b @Thomas-Giraud Thomas-Giraud committed with lakeman May 24, 2011
Showing with 107 additions and 105 deletions.
  1. +4 −6 AndroidManifest.xml
  2. +92 −80 src/org/servalproject/dna/OpDT.java
  3. +11 −19 src/org/servalproject/dt/Receiver.java
View
@@ -127,12 +127,10 @@
<data android:path="org.sipdroid.sipua" />
</intent-filter>
</receiver>
- <receiver android:name="dt.Receiver">
- <intent-filter>
- <action android:name="android.intent.action.PICK" />
- <category android:name="android.intent.category.DEFAULT" />
- <data android:mimeType="vnd.servalproject.DTSMS/vnd.servalproject.DTSMS-text" />
- </intent-filter>
+ <receiver android:name=".dt.Receiver">
+ <intent-filter>
+ <action android:name="org.servalproject.DT"/>
+ </intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
@@ -1,80 +1,92 @@
-package org.servalproject.dna;
-
-import java.nio.ByteBuffer;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.servalproject.dna.OpSimple.Code;
-
-public class OpDT implements Operation {
- enum DTtype{
- SMS((byte)0x00),
- TwitterMessage((byte)0x01);
-
- byte dtType;
- DTtype(byte dtType){
- this.dtType=dtType;
- }
- }
- private static Map<Byte, DTtype> dtTypes=new HashMap<Byte, DTtype>();
- static{
- for (DTtype t:DTtype.values()){
- dtTypes.put(t.dtType, t);
- }
- }
- public static DTtype getType(byte b){
- return dtTypes.get(b);
- }
-
- DTtype messageType;
- String message;
- String emitterPhoneNumber;
- String recipientPhoneNumber;
-
- OpDT(){}
- public OpDT(String message, String emitterPhoneNumber, DTtype messageType){
- this.messageType=messageType;
- // Length of the 2 next strings are stored in a byte, so we cut them if their length > 255
- if (emitterPhoneNumber.length()>255)
- this.emitterPhoneNumber=emitterPhoneNumber.substring(0, 255);
- else
- this.emitterPhoneNumber=emitterPhoneNumber;
- if (message.length()>255)
- this.message=message.substring(0, 255);
- else
- this.message=message;
- }
-
- static byte getCode(){return (byte)0x04;}
-
- @Override
- public void parse(ByteBuffer b, byte code) {
- this.messageType = getType(b.get());
- int emitterPhoneNumberLen = ((int)b.get())&0xff;
- int messageLen = ((int)b.get())&0xff;
- this.emitterPhoneNumber = new String(b.array(), b.arrayOffset()+b.position(), emitterPhoneNumberLen);
- b.position(b.position()+emitterPhoneNumberLen);
- this.message = new String(b.array(), b.arrayOffset()+b.position(), messageLen);
- b.position(b.position()+messageLen);
- }
-
- @Override
- public void write(ByteBuffer b) {
- b.put(getCode());
- b.put(messageType.dtType);
- b.put((byte)emitterPhoneNumber.length());
- b.put((byte)message.length());
- b.put(emitterPhoneNumber.getBytes());
- b.put(message.getBytes());
- }
-
- @Override
- public boolean visit(Packet packet, OpVisitor v) {
- return v.onDT(packet, this.messageType, this.emitterPhoneNumber, this.message);
- }
-
- @Override
- public String toString() {
- return "DT type "+messageType+" from "+emitterPhoneNumber+" : '"+message+"'";
- }
-}
+package org.servalproject.dna;
+
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+
+public class OpDT implements Operation {
+ public enum DTtype {
+ SMS((byte) 0x00), TwitterMessage((byte) 0x01);
+
+ byte dtType;
+
+ DTtype(final byte dtType) {
+ this.dtType = dtType;
+ }
+ }
+
+ public static Map<Byte, DTtype> dtTypes = new HashMap<Byte, DTtype>();
+ static {
+ for (DTtype t : DTtype.values()) {
+ dtTypes.put(t.dtType, t);
+ }
+ }
+
+ public static DTtype getType(final byte b) {
+ return dtTypes.get(b);
+ }
+
+ DTtype messageType;
+ String message;
+ String emitterPhoneNumber;
+ String recipientPhoneNumber;
+
+ OpDT() {
+ }
+
+ public OpDT(final String message, final String emitterPhoneNumber,
+ final DTtype messageType) {
+ this.messageType = messageType;
+ // Length of the 2 next strings are stored in a byte, so we cut them if
+ // their length > 255
+ if (emitterPhoneNumber.length() > 255) {
+ this.emitterPhoneNumber = emitterPhoneNumber.substring(0, 255);
+ } else {
+ this.emitterPhoneNumber = emitterPhoneNumber;
+ }
+ if (message.length() > 255) {
+ this.message = message.substring(0, 255);
+ } else {
+ this.message = message;
+ }
+ }
+
+ static byte getCode() {
+ return (byte) 0x04;
+ }
+
+ @Override
+ public void parse(final ByteBuffer b, final byte code) {
+ this.messageType = getType(b.get());
+ int emitterPhoneNumberLen = (b.get()) & 0xff;
+ int messageLen = (b.get()) & 0xff;
+ this.emitterPhoneNumber = new String(b.array(), b.arrayOffset()
+ + b.position(), emitterPhoneNumberLen);
+ b.position(b.position() + emitterPhoneNumberLen);
+ this.message = new String(b.array(), b.arrayOffset() + b.position(),
+ messageLen);
+ b.position(b.position() + messageLen);
+ }
+
+ @Override
+ public void write(final ByteBuffer b) {
+ b.put(getCode());
+ b.put(this.messageType.dtType);
+ b.put((byte) this.emitterPhoneNumber.length());
+ b.put((byte) this.message.length());
+ b.put(this.emitterPhoneNumber.getBytes());
+ b.put(this.message.getBytes());
+ }
+
+ @Override
+ public boolean visit(final Packet packet, final OpVisitor v) {
+ return v.onDT(packet, this.messageType, this.emitterPhoneNumber,
+ this.message);
+ }
+
+ @Override
+ public String toString() {
+ return "DT type " + this.messageType + " from "
+ + this.emitterPhoneNumber + " : '" + this.message + "'";
+ }
+}
@@ -6,18 +6,17 @@
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
-import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
+import android.util.Log;
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
- if ((intent.getAction().equals("android.intent.action.PICK"))
- & (intent.getType()
- .equals("vnd.servalproject.DTSMS/vnd.servalproject.DTSMS-text"))) {
+ Log.i("Receiver", "Intent received " + intent.getAction());
+ if (intent.getAction().equals("org.servalproject.DT")) {
String sender = intent.getExtras().getString("number");
String content = intent.getExtras().getString("content");
this.writeSMS(sender, content, context);
@@ -39,25 +38,18 @@ private void writeSMS(final String sender, final String content,
.getSystemService(ns);
int icon = R.drawable.icon;
- CharSequence tickerText = "Digital Telegram - New message";
long when = System.currentTimeMillis();
- Notification notification = new Notification(icon, tickerText, when);
- // Context context = getApplicationContext();
- CharSequence contentTitle = "Digital Telegram";
- CharSequence contentText = "You have a new message";
- Intent notificationIntent = new Intent("android.intent.action.MAIN");
+ Notification notification = new Notification(icon,
+ "Digital Telegram - New message", when);
+ Intent notificationIntent = new Intent("android.intent.action.VIEW");
+ notificationIntent.setData(Uri
+ .parse("content://mms-sms/conversations/"));
// Lauch Messaging when the user clicks on the notification
- // notificationIntent.setComponent(new
- // ComponentName("com.android.mms","com.android.mms.ui.ConversationList"));
- // Lauch SmsDroid when the user clicks on the notification
- notificationIntent.setComponent(new ComponentName(
- "de.ub0r.android.smsdroid",
- "de.ub0r.android.smsdroid.ConversationList"));
- PendingIntent contentIntent = PendingIntent.getBroadcast(context, 0,
+ PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
- notification.setLatestEventInfo(context, contentTitle, contentText,
- contentIntent);
+ notification.setLatestEventInfo(context, "Digital Telegram", sender
+ + ": " + content, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(1, notification);
}

0 comments on commit 7e47cfc

Please sign in to comment.