2012-09-28 58 views
-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(); 

    } 
} 

如何改變舉杯通知狀態欄?謝謝!

+0

谷歌可以幫助您與此有關。當你遇到特定的問題時,*當你尋求幫助時*。 – Eric

回答

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