mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Fixed: Fix Settings.ACTION_*
permission requests for non-activity contexts
This was caused by ce12b8ad
Closes #2769
This commit is contained in:
@@ -357,6 +357,11 @@ public class PermissionUtils {
|
|||||||
intent.addCategory("android.intent.category.DEFAULT");
|
intent.addCategory("android.intent.category.DEFAULT");
|
||||||
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
||||||
|
|
||||||
|
// Flag must not be passed for activity contexts, otherwise onActivityResult() will not be called with permission grant result.
|
||||||
|
// Flag must be passed for non-activity contexts like services, otherwise "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag" exception will be raised.
|
||||||
|
if (!(context instanceof Activity))
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
|
||||||
Error error;
|
Error error;
|
||||||
if (requestCode >=0)
|
if (requestCode >=0)
|
||||||
error = ActivityUtils.startActivityForResult(context, requestCode, intent, true, false);
|
error = ActivityUtils.startActivityForResult(context, requestCode, intent, true, false);
|
||||||
@@ -474,6 +479,11 @@ public class PermissionUtils {
|
|||||||
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
|
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
|
||||||
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
||||||
|
|
||||||
|
// Flag must not be passed for activity contexts, otherwise onActivityResult() will not be called with permission grant result.
|
||||||
|
// Flag must be passed for non-activity contexts like services, otherwise "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag" exception will be raised.
|
||||||
|
if (!(context instanceof Activity))
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
|
||||||
if (requestCode >=0)
|
if (requestCode >=0)
|
||||||
return ActivityUtils.startActivityForResult(context, requestCode, intent);
|
return ActivityUtils.startActivityForResult(context, requestCode, intent);
|
||||||
else
|
else
|
||||||
@@ -549,6 +559,11 @@ public class PermissionUtils {
|
|||||||
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
||||||
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
||||||
|
|
||||||
|
// Flag must not be passed for activity contexts, otherwise onActivityResult() will not be called with permission grant result.
|
||||||
|
// Flag must be passed for non-activity contexts like services, otherwise "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag" exception will be raised.
|
||||||
|
if (!(context instanceof Activity))
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
|
||||||
if (requestCode >=0)
|
if (requestCode >=0)
|
||||||
return ActivityUtils.startActivityForResult(context, requestCode, intent);
|
return ActivityUtils.startActivityForResult(context, requestCode, intent);
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user