-1

SMSアプリを作っています。これはクラス受信SMSです:

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 に答える