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