Android 使我的通知可点击
我制作了一个由alarmmanager触发的应用程序,只有通知是不可点击的。我该怎么做 来自MainActivity的代码:Android 使我的通知可点击,android,android-intent,android-notifications,android-pendingintent,Android,Android Intent,Android Notifications,Android Pendingintent,我制作了一个由alarmmanager触发的应用程序,只有通知是不可点击的。我该怎么做 来自MainActivity的代码: private void scheduleNotification(Notification notification, int delay) { Intent notificationIntent = new Intent(this, NotificationPublisher.class); notificationIntent.putExtra(N
private void scheduleNotification(Notification notification, int delay) {
Intent notificationIntent = new Intent(this, NotificationPublisher.class);
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID, 1);
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
long futureInMillis = SystemClock.elapsedRealtime() + delay;
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);
}
private Notification getNotification(String titel, String content) {
Notification.Builder builder = new Notification.Builder(this);
builder.setContentTitle(titel);
builder.setContentText(content);
builder.setSmallIcon(R.mipmap.ic_launcher);
return builder.build();
}
我的通知发布类中的代码:
public class NotificationPublisher extends BroadcastReceiver {
public static String NOTIFICATION_ID = "notification-id";
public static String NOTIFICATION = "notification";
public void onReceive(Context context, Intent intent)
{
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = intent.getParcelableExtra(NOTIFICATION);
int id = intent.getIntExtra(NOTIFICATION_ID, 0);
notificationManager.notify(id, notification);
}
}您可能正在寻找该方法
setContentIntent(PROVIDE_YOUR_PENDING_INTENT);
您需要提供一个挂起的意图,当用户单击通知时,您希望将其重定向到何处
参考资料:您可能正在寻找该方法
setContentIntent(PROVIDE_YOUR_PENDING_INTENT);
您需要提供一个挂起的意图,当用户单击通知时,您希望将其重定向到何处
参考资料:也许你是在为这个发愁?builder.setContentIntentresultPendingIntent;当用户点击它时,它应该怎么做?也许你是在为此而发疯?builder.setContentIntentresultPendingIntent;当用户点击它时,它应该做什么?