package fptu.ninhtbm.demonotification; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.NotificationCompat; import androidx.core.app.RemoteInput; public class ReplyActivity extends AppCompatActivity { private static final String CHANNEL_ID = "SECOND_CHANNEL_ID"; private static final String NOTIFICATION_CHANNEL = "SECOND_CHANNEL"; private static final String REMOTE_TEXT_KEY = "REMOTE_TEXT_KEY"; private int count = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_reply); Intent intent = getIntent(); Bundle b = RemoteInput.getResultsFromIntent(intent); if (b != null) { String s = b.getString(REMOTE_TEXT_KEY); Button button = findViewById(R.id.btn_reply); button.setText(s); Toast.makeText(this, s, Toast.LENGTH_SHORT).show(); } } @RequiresApi(api = Build.VERSION_CODES.O) public void onSendNotification(View view) { RemoteInput remoteInput = new RemoteInput.Builder(REMOTE_TEXT_KEY).setLabel("nhét chữ vào đây nè").build(); Intent intent = new Intent(this, ReplyActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action action = new NotificationCompat.Action.Builder(android.R.drawable.ic_dialog_info, "Reply", pendingIntent) .addRemoteInput(remoteInput).build(); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setColor(Color.RED) .setSmallIcon(android.R.drawable.ic_dialog_info) .setContentTitle("My Notification") .setContentText("Test inline reply") .addAction(action); Notification notification = builder.build(); NotificationChannel channel = new NotificationChannel(CHANNEL_ID, NOTIFICATION_CHANNEL, NotificationManager.IMPORTANCE_DEFAULT); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(channel); notificationManager.notify(200 + count++, notification); } }