Olá, eu gostaria de pedir ajuda pois eu montei um app com um cronômetro e depois de muito tempo consegui habilitar notificações para o Android Oreo+, porém eu não consigo acessar a activity do cronômetro através dessa notificação e gostaria também se puder, me ajudar a abrir a activity do cronômetro via notificação sem que o mesmo reinicie
segue abaixo o código
NotificationHelper.java
public NotificationHelper(Context base) {
super(base);
createChannels();
}
private void createChannels() {
NotificationChannel myChannel = new NotificationChannel(MY_CHANNEL_ID, MY_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
myChannel.enableLights(true);
getManager().createNotificationChannel(myChannel);
}
public NotificationManager getManager() {
if (manager == null)
manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
return manager;
}
public Notification.Builder getmyChannelNotification(String title, String body) {
return new Notification.Builder(getApplicationContext(), MY_CHANNEL_ID)
.setAutoCancel(false)
.setContentText("Acesso rápido ao app")
.setSmallIcon(R.drawable.timer_notification);
}
}
chronometer.java
private NotificationChannel NotificationChannel;
private TextView Title;
private TextView Content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chronometer);
helper = new NotificationHelper(this);
Title = (TextView)findViewById(R.id.Title);
Content = (TextView)findViewById(R.id.Content);
notificationbtn = (Button)findViewById(R.id.notificationbtn);
notificationbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String title = Title.getText().toString();
String content = Content.getText().toString();
Notification.Builder builder = helper.getmyChannelNotification(title, content );
helper.getManager().notify(new Random().nextInt(),builder.build());
}
});