Stack Overflow에서 찾은 답변을 사용했지만 제대로 작동하지 않았습니다. 그러나 근본적으로, 나는 두 가지를하기 위해 나의 통지가 필요하다. 하나는 알림 자체를 클릭 할 때 앱을 다시 열어야하며 AddAction을 클릭하면 알림을 닫아야합니다.안드로이드 알림이 AddAction에서 닫히지 않습니다.
알림은 클릭 할 때 앱을 엽니 다.이 내용은 정확하지만 AddAction ('완료')을 클릭하면 앱이 똑같이 수행됩니다. 알림을 닫는 작업 대신 알림 자체와 마찬가지로 앱을 엽니 다. 무엇이 잘못 될 수 있습니까?
public void onInput(MaterialDialog dialog, CharSequence input) {
//notification body
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0,
new Intent(getApplicationContext(), MainActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP),
0);
//Rest of Notification
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(input.toString())); //BigText
builder.setOngoing(true); //Make persistent
builder.setContentIntent(pendingIntent); //OnClick for Reopening App
builder.setSmallIcon(R.drawable.ic_note);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
builder.setContentTitle("Remember!");
builder.setContentText(input.toString()); //Get text from dialog input
Intent closeIntent = new Intent(getApplicationContext(), MainActivity.class);
closeIntent.putExtra(getPackageName(), NOTIFICATION_ID);
PendingIntent closeBtn = PendingIntent.getActivity(getApplicationContext(), 0, closeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.ic_action_name, "Done", closeBtn); //Action for the closer
notificationManager.notify(NOTIFICATION_ID, builder.build());
//toast
Toast.makeText(MainActivity.this, "Done! Reminder has been set. Check your Notification Bar! :)",
Toast.LENGTH_LONG).show();
//Close app when done entering in text
finish();
}
버튼을 추가 한 이유는 알림이 지속적이고 결코 스왑 할 수 없기 때문입니다. 알림을 지속적으로 유지하면서 작동시키는 방법을 파악할 수 없기 때문에 문제를 해결할 수 있습니다. – MJonesDev