-1

我做短信应用。这是类接收短信:

public class TerimaSMS extends BroadcastReceiver {
    @Override

    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();

        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]);
        }

        // show first message
            Toast toast = Toast.makeText(context,
                    "SMS Received : " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
                    toast.show();   

    }
}

如何将吐司更改为状态栏中的通知?谢谢!

4

2 回答 2

2

添加这个而不是你的吐司:

NotificationManager mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Context context = getApplicationContext();          
Intent notificationIntent = new Intent(YourClass.this, YourClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(YourClass.this, 0, notificationIntent, 0);
Notification notification = new Notification(R.drawable.icon, "SMS Received : " + smsMessage[0].getMessageBody(), System.currentTimeMillis());
notification.setLatestEventInfo(context, "title", "content", contentIntent);
mNotificationManager.notify(1, notification);
于 2012-09-28T19:01:57.063 回答
0

这是一个链接,它将帮助您获得通知:- http://mobiforge.com/developing/story/sms-messaging-android

于 2012-09-28T18:58:30.530 回答