I am taking user to Notification center to control their push notifications preferences and read it from my app, and set to a switch toggle. I have different action for Lollipop and Oreo, but currently application is crashing for Android Pie 9.0. How can I fix that issue?
public void onPushSwitchChanged(View v){
if(v.isPressed()){
Intent intent = new Intent();
if(android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1){
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
intent.putExtra("android.provider.extra.APP_PACKAGE", mContext.getPackageName());
}else if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
intent.putExtra("app_package", mContext.getPackageName());
intent.putExtra("app_uid", mContext.getApplicationInfo().uid);
}else {
intent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("package:" + mContext.getPackageName()));
}
mContext.startActivity(intent);
}
}
And the error is
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.