SMS を受信すると、ステータス バーからの SMS 通知をクリックすると、ステータス バーに SMS の通知が表示されます。ViewMessageListActivity (私の会話ログ) は開きません。このアクティビティを開くにはどうすればよいですか。
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.widget.Toast;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class SmsReceiver extends BroadcastReceiver {
static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
int notificationID = 1;
@Override
public void onReceive(Context context, Intent intent)
{
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (intent.getAction().equals(ACTION)) {
StringBuilder sb = new StringBuilder();
String from = new String();
String body = new String();
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
for (Object pdu : pdus){
SmsMessage messages = SmsMessage.createFromPdu((byte[]) pdu);
sb.append(messages.getDisplayOriginatingAddress());
from = messages.getDisplayOriginatingAddress();
sb.append(messages.getDisplayMessageBody());
body= messages.getDisplayMessageBody();
//Log.i(LOG_TAG, "[SMSApp] onReceiveIntent: " + sb);
//abortBroadcast();
}// end for
}//end if
int icon = R.drawable.stat_notify_sms;
CharSequence tickerText = from + ": " + body;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
CharSequence contentTitle = "New Cybernetx Secure Text Message";
CharSequence contentText = from + " " + body;
Intent notificationIntent = new Intent();
PendingIntent contentIntent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.vibrate = new long[] { 100, 250, 100, 500};
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(notificationID, notification);
// intent.setAction(SendReceiveService.RECEIVE_SMS_ACTION);
// intent.setClass(arg0, ViewMessageListActivity.class);
// intent.putExtra("notificationID", notificationID);
// arg0.startService(intent);
// PendingIntent contentIntent =
// PendingIntent.getActivity(arg0, 0, i, 0);
/* Start the Main-Activity */
Intent i = new Intent(context, ViewMessageListActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}//end if
}
}