tôi đã thiết lập một thông báo cho ứng dụng của tôi và mã đi như thế này:Buttons Notification nhấp chuột không làm việc
public int getNotification(View view) {
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(getActivity() ,RouteMap.class);
intent.putExtra("Stop Ride",true);
PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), (int) System.currentTimeMillis(), intent, 0) ;
if (Build.VERSION.SDK_INT < 16) {
getToast("API below 16 ...notification not supported");
} else {
Notification notify = new Notification.Builder(getActivity())
.setSmallIcon(R.drawable.icon1)
.setContentTitle("Car Rental")
.setContentText("Click to view ")
.setOngoing(true)
.setContentIntent(pendingIntent)
.addAction(R.drawable.icon3,"View ",pendingIntent)
.addAction(R.drawable.alert_icon,"Stop Ride", pendingIntent)
.build();
notificationManager.notify(notificationID, notify);
}
return notificationID;
}
public void removeNotification() {
NotificationManager manager = (NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(
notificationID);
getToast("Notification Removed");
}
ứng dụng hiển thị các thông báo nhưng không thực hiện bất kỳ hành động khi nút trên thông báo được nhấp xin vui lòng giúp đỡ tôi nếu một cái gì đó được thêm vào mã của tôi.
Cập nhật: Như Phương pháp này là bên trong một lớp mảnh
Tôi đã thay đổi một số mã của tôi như đề xuất dưới đây nhưng nó làm việc:
public int getNotification(View view) {
// NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(getActivity(), RouteMap.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), 0, intent, 0);
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if (Build.VERSION.SDK_INT < 16) {
getToast("API below 16 ...notification not supported");
} else {
Notification notify = new Notification.Builder(getActivity())
.setSmallIcon(R.drawable.icon12)
.setContentTitle("Car Rental")
.setContentText("Click to view ")
.setOngoing(true)
.setSound(soundUri)
.setContentIntent(pendingIntent)
.addAction(R.drawable.icon3, "View ", pendingIntent)
.addAction(R.drawable.alert_icon, "Stop Ride", pendingIntent)
.build();
notificationManager.notify(notificationID, notify);
}
return notificationID;
}
Thanks in advance ..
bạn có thể muốn kiểm tra [this] (http://stackoverflow.com/questions/11270898/how-to-execute-a-method-by-clicking-a-notification). – zionpi