0
這是我第一次發佈一個問題,我希望能做好。我做一個Android應用程序和我正在實現的一件事是,當通知來了,如果我在通知欄上選擇了它,它會向我顯示帶有消息的alertdialog,第一次工作,但是當我發送其他消息,它總是顯示第一條消息發送它。Alertdialog推送信息不變,始終是第一個
這是使用上的GCMIntentService代碼IM:
private void generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
varDb =new VSCSQLiteHelper(context, "Probe1", null, 1);
String title = context.getString(R.string.app_name);
if(tts == null) {
tts = new TextToSpeech(this.getApplicationContext(), this);
}
Calendar c = Calendar.getInstance();
hora = c.get(Calendar.HOUR_OF_DAY);
db = varDb.getWritableDatabase();
config = db.rawQuery("SELECT * FROM Config_prob1",null);
config.moveToFirst();
if(hora >= config.getInt(2) && hora <= config.getInt(3)){
if(config.getInt(0) == 1 && config.getInt(1) == 1){
notificationIntent = new Intent(context, Mensaje.class);
notificationIntent.putExtra("message", message);
tts.speak(message, TextToSpeech.QUEUE_ADD, null);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}else if(config.getInt(1) == 1){
notificationIntent = new Intent(context, Mensaje.class);
notificationIntent.putExtra("message", message);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}else{
tts.speak(message, TextToSpeech.QUEUE_ADD, null);
}
}
config.close();
db.close();
}
以及類,顯示消息我有:
public class Mensaje extends Activity{
private Bundle bundle = null;
private String mensaje = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mensaje);
bundle = getIntent().getExtras();
mensaje = bundle.getString("message");
AlertDialog.Builder builder = new AlertDialog.Builder(Mensaje.this);
builder.setMessage(mensaje)
.setTitle("Mensaje recibido")
.setIcon(R.drawable.logo)
.setCancelable(false)
.setNeutralButton("Aceptar",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
Mensaje.this.finish();
}
});
builder.create();
builder.show();
}
@Override
public void onDestroy() {
Log.i("Mensaje", "onDestroy()");
super.onDestroy();
}
}
我試圖打印該消息,該消息那是在的GCMINtent是好的,但在其他班級總是第一個。
感謝您的幫助。
It Works !!,謝謝 –