我制作短信应用程序。这是课程接收短信:
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();
}
}
如何在状态栏中更改通知的烤面包?谢谢!
答案 0 :(得分: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);
答案 1 :(得分:0)
这是一个链接,这将有助于您发出通知: - http://mobiforge.com/developing/story/sms-messaging-android