我的問題是,我能夠從服務器獲取通知,但來自服務器的消息不刷新我的手機任何通知是第一次相同的消息我得到所有時間 。這是我的C2DMMessageReceiver代碼& MessageReceivedActivity如下。消息不刷新推送通知
public class C2DMMessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.w("C2DM", "Message Receiver called");
if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
Log.w("C2DM", "Received message");
final String payload = intent.getStringExtra("payload");
createNotification(context, payload);
}
}
public void createNotification(Context context, String payload) {
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,
"Message received", System.currentTimeMillis());
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(context, MessageReceivedActivity.class);
intent.putExtra("payload", payload);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, 0);
notification.setLatestEventInfo(context, "Message",
"New message received", pendingIntent);
notificationManager.notify(0, notification);
}
}
public class MessageReceivedActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_result);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String message = extras.getString("payload");
if (message != null && message.length() > 0) {
TextView view = (TextView) findViewById(R.id.result);
view.setText(message);
}
}
super.onCreate(savedInstanceState);
}
}
你能提供更多的代碼嗎?像你把這個代碼放在哪裏? 「onCreate」或onResume以及您做了哪種類型的推送? – daigoor 2012-03-13 15:14:10
好吧diagor可以給我你的電子郵件ID? – user1249134 2012-03-14 04:09:06