mirror of
				https://github.com/fankes/termux-app.git
				synced 2025-10-25 13:19:21 +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.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; | ||||
|         if (requestCode >=0) | ||||
|             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.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) | ||||
|             return ActivityUtils.startActivityForResult(context, requestCode, intent); | ||||
|         else | ||||
| @@ -549,6 +559,11 @@ public class PermissionUtils { | ||||
|         Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); | ||||
|         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) | ||||
|             return ActivityUtils.startActivityForResult(context, requestCode, intent); | ||||
|         else | ||||
|   | ||||
		Reference in New Issue
	
	Block a user