我的问题是,我能够从服务器获取通知,但来自服务器的消息不刷新我的手机任何通知是第一次相同的消息我得到所有时间 。这是我的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