@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
final Intent intent = new Intent(MainActivity.this, AlertActivity.class);
final PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this);
builder.setContentText("Click here");
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentTitle(getString(R.string.app_name));
builder.addAction(R.mipmap.ic_launcher, "Test", pendingIntent);
builder.setAutoCancel(true);
NotificationManagerCompat.from(MainActivity.this).notify(0, builder.build());
}
});
}
또한 builder.addAction()을 제거하여 실험했지만 알림을 클릭해도 아무 효과가 없습니다. 조치를 추가하지 않고 통지를 클릭하면 어떻게 사용자를 특정 활동으로 유도 할 수 있습니까? 또한, 두 경우 모두; 수동으로 슬라이드하여 제거하지 않으면 알림을 닫을 수 없습니다.builder.setAutoCancel (true) 작동하지 않습니다.
'notification.clear (id)'를 사용하는 방법과 위치를 보여줍니다. – Apurva
onCreate();에서 알림 빌더를 직접 만들었습니다. 여전히 autoCancel이 작동하지 않습니다. clear()을 호출하는 방법? –
알림 관리자에서 알림을 호출하면 ID (나중에 알림에 액세스 할 때 사용할 수있는 고유 ID)가 표시됩니다 (알림 관리자에서 제공). notify (int id, 알림 알림) 취소하려면 동일한 ID로 을 취소 할 수 있습니다. 기본적으로 ID를 추적하거나 ID를 번들에 넣어야합니다. –