0

In Xiaomi phones, when I try to redirect to a browser on the click of a notification using the following code :

 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            try {
                context.startActivity(intent);
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, e.getMessage());
            }

Redirect is not working and it is throwing an error that "Calling startActivity() from outside of an Activity context requires the
FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?".

I am

It is working fine in other phones. Can anyone help in solving this?

Aman Kush
  • 91
  • 2
  • 11

1 Answers1

0

This happens when you call startActivity out the the activity class. use below code for your problem it will work. for reference you can see

FLAG_ACTIVITY_NEW_TASK clarification needed

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
 intent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
            try {
                context.startActivity(intent);
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, e.getMessage());
            }
Salman Aziz
  • 191
  • 4