1
Hello, I would like to ask for help because I built an app with a stopwatch and after a long time managed to enable notifications for Android Oreo+, but I can’t access the stopwatch Activity through this notification and would also like if you can, help me open the timer Activity via notification without restarting it
follows below the code
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());
}
});