Go back to app after user sets Notification Listener permission

250 Views Asked by At

I need the user to enable the Notification Listener permission for my app. For now i just start a new activity as below, but would like that when then user allows the permission, it goes back to my activity by itself?

startActivity(new Intent(android.provider.Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
1

There are 1 best solutions below

0
On BEST ANSWER

I figured it out by creating a handler that check every half second if the notification listener contains my package and when true opens my activity again.

final Handler handler = new Handler();
final int delay = 500; //milliseconds

mRunnable = new Runnable() {
  @Override
  public void run() {
    if((!NotificationManagerCompat.getEnabledListenerPackages(getActivity()).contains(BuildConfig.APPLICATION_ID))){
           handler.postDelayed(mRunnable, delay);
    }else{
           Intent LaunchIntent = getActivity().getIntent();
           startActivity(LaunchIntent);
           //LaunchIntent.finish();
           handler.removeCallbacks(mRunnable);
    }

  }
};
handler.postDelayed(mRunnable, delay);*/