Show notification when receive sms

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Show notification when receive sms

Postby binhsoledas » Tue Nov 10, 2009 8:33 am

Dear all!
I have some code as below:
public class SMSReceiver extends BroadcastReceiver {

static final String ACTION = "android.intent.action.BOOT_COMPLETED";
private NotificationManager mNotificationManager;
private int YOURAPP_NOTIFICATION_ID;
private Handler handler = new Handler();
static Context con;
/**
* @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
*/
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
con = context;
Toast toast1 = Toast.makeText(context, "received sms ", Toast.LENGTH_LONG);
toast1.show();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++) {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}


showNotification(context, R.drawable.alert_dark_frame, "hello", "world", false);

}

void showNotification(Context context, int statusBarIconID, String string, String string2, boolean showIconOnly) {
int icon = R.drawable.alert_dark_frame;
CharSequence tickerText1 = "Hello"; // ticker-text
long when = System.currentTimeMillis(); // notification time // application Context
CharSequence contentTitle = "My notification"; // expanded message title
CharSequence contentText = "Hello World!"; // expanded message text

Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, tickerText1, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(YOURAPP_NOTIFICATION_ID,notification);
}
}


I send sms to this application but i can't show notification and have error when show notification. I don't know where is problem. Who know. Hope to help me!
binhsoledas
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Sep 16, 2009 4:16 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 8 guests