0
嘿家伙看看这个代码...不能保存短信彩信OOR
一切工作正常,但是当过我得到短信通知我下拉抽屉,点击它....没有任何反应.. 。 我能做些什么来存储的短信,并显示其作为Android的股票消息应用程序显示themmm ...
请帮助
public void onReceive(Context context, Intent intent)
{
/* As we want to display a Notification, we the NotificationManager */
NotificationManager nm =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (intent.getAction().equals(ACTION)) {
// if(message starts with SMStretcher recognize BYTE)
StringBuilder sb = new StringBuilder();
String from = new String();
String body = new String();
/* The SMS-Messages are 'hiding' within the extras of the Intent. */
Bundle bundle = intent.getExtras();
if (bundle != null) {
/* Get all messages contained in the Intent*/
Object[] pduObj = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pduObj.length];
for(int i=0;i<pduObj.length;i++)
{
messages[i]=SmsMessage.createFromPdu((byte[])pduObj[i]);
}
/* Feed the StringBuilder with all Messages found. */
for (SmsMessage currentMessage : messages){
from = currentMessage.getDisplayOriginatingAddress();
body = currentMessage.getDisplayMessageBody();
/* Sender-Number */
sb.append(from);
/* Actual Message-Content */
sb.append(body);
}
}
/* Logger Debug-Output */
Log.i(LOG_TAG, "[SMSApp] onReceive: " + sb);
/* Show the Notification containing the Message. */
int icon=R.drawable.messageicon;
CharSequence tickerText = from + ": " + body;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
CharSequence contentTitle = from;
CharSequence contentText = sb.toString();
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;
nm.notify(1, notification);
this.abortBroadcast();
/* Start the Main-Activity
Intent i = new Intent(context, SMS.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);*/
}
}
}
但如果我不为u说,打开主SMS发送班级菜单......但是在接收到短信之前我没有发送任何短信... – kashifmehmood 2012-02-25 07:55:30
我不确定你在这里做什么。 notificationIntent是用户单击通知后通知管理器使用的意图。你把它想要的活动放进去。 – njzk2 2012-02-27 09:24:32