我正在将用户带到通知中心来控制他们的推送通知首选项并从我的应用程序中读取它,并设置为切换切换。我对Lollipop和Oreo有不同的操作,但目前应用程序崩溃了Android Pie 9.0。我该如何解决这个问题?
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);
}
}
错误是
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.
更新,
我通过添加修复了这个问题,
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
在我的第一个if块中。