我創建一個服務推送通知:動作按鈕不起作用的Android
AppointmentService.java
Intent intent = new Intent(AppointmentService.this, ReAppointmentService.class);
intent.putExtra("id", id);
PendingIntent pIntent = PendingIntent.getService(AppointmentService.this, 0, intent, 0);
Notification n = new NotificationCompat.Builder(AppointmentService.this)
.setContentTitle((String) snapshot.child("name").getValue())
.setContentText("Hey!")
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.addAction(R.drawable.ic_action_reply_light, "Hey yo!", pIntent)
.build();
NotificationManager notificationManager =
(NotificationManager) HeyService.this.getSystemService(Activity.NOTIFICATION_SERVICE);
notificationManager.notify(getNotificationID(id), n);
ReAppointmentService.java @覆蓋 公衆的IBinder onBind (意圖arg0) { return null; }
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
Bundle extras = intent.getExtras();
String id = extras.getString("id");
gc = new GlobalContents(this);
Firebase send = new Firebase("https://appointmentapp.firebaseio.com/app/"+id);
Firebase ref = send.push();
ref.runTransaction(new Transaction.Handler()
{
@Override
public Transaction.Result doTransaction(MutableData ref)
{
ref.child("date").setValue(String.valueOf((new GregorianCalendar()).getTimeInMillis()));
ref.child("name").setValue(gc.getName());
ref.child("from").setValue(gc.getID());
ref.child("seen").setValue(false);
return Transaction.success(ref);
}
@Override
public void onComplete(FirebaseError error, boolean committed, DataSnapshot currentData) {
}
});
return START_NOT_STICKY;
}
該通知通常用操作按鈕顯示。但是,當我點擊按鈕時,什麼都沒有發生(我嘗試在ReAppointmentService上放置一些日誌,但它不起作用)。
什麼問題?
我已經理解了這個問題,但是這不起作用。接收PendingIntent的服務可能有問題嗎? –
你必須在你的帖子中解釋更多關於'ReAppointmentService'中的日誌指出的內容 - extras.hasExtra(「id」)'是'false'? 'extras.getString(「id」)'爲空?你正在將Intent放入Intent中的ID實際上是一個String嗎? – ianhanniballake
ReAppointmentService似乎沒有被訪問。 –