Take screenshot action added
This commit is contained in:
		| @@ -266,6 +266,10 @@ | ||||
|             <intent-filter> | ||||
|                 <action android:name="android.accessibilityservice.AccessibilityService" /> | ||||
|             </intent-filter> | ||||
|  | ||||
|             <meta-data | ||||
|                 android:name="android.accessibilityservice" | ||||
|                 android:resource="@xml/config_accessibility_service" /> | ||||
|         </service> | ||||
|  | ||||
|     </application> | ||||
|   | ||||
| @@ -251,6 +251,10 @@ | ||||
|             <intent-filter> | ||||
|                 <action android:name="android.accessibilityservice.AccessibilityService" /> | ||||
|             </intent-filter> | ||||
|  | ||||
|             <meta-data | ||||
|                 android:name="android.accessibilityservice" | ||||
|                 android:resource="@xml/config_accessibility_service" /> | ||||
|         </service> | ||||
|  | ||||
|     </application> | ||||
|   | ||||
| @@ -250,6 +250,10 @@ | ||||
|             <intent-filter> | ||||
|                 <action android:name="android.accessibilityservice.AccessibilityService" /> | ||||
|             </intent-filter> | ||||
|  | ||||
|             <meta-data | ||||
|                 android:name="android.accessibilityservice" | ||||
|                 android:resource="@xml/config_accessibility_service" /> | ||||
|         </service> | ||||
|  | ||||
|     </application> | ||||
|   | ||||
| @@ -640,6 +640,9 @@ public class Action | ||||
| 				case copyToClipboard: | ||||
| 					Actions.copyToClipboard(context, Miscellaneous.replaceVariablesInText(this.getParameter2(), context)); | ||||
| 					break; | ||||
| 				case takeScreenshot: | ||||
| 					Actions.takeScreenshot(); | ||||
| 					break; | ||||
| 				default: | ||||
| 					Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3); | ||||
| 					break; | ||||
|   | ||||
| @@ -2127,7 +2127,7 @@ public class ActivityManageRule extends Activity | ||||
| 			else if(types[i].toString().equals(Action_Enum.copyToClipboard.toString())) | ||||
| 				items.add(new Item(typesLong[i].toString(), R.drawable.clipboard)); | ||||
| 			else if(types[i].toString().equals(Action_Enum.takeScreenshot.toString())) | ||||
| 				items.add(new Item(typesLong[i].toString(), R.drawable.clipboard)); | ||||
| 				items.add(new Item(typesLong[i].toString(), R.drawable.copier)); | ||||
| 			else | ||||
| 				items.add(new Item(typesLong[i].toString(), R.drawable.placeholder)); | ||||
| 		} | ||||
|   | ||||
| @@ -333,31 +333,33 @@ public class ActivityPermissions extends Activity | ||||
|     { | ||||
|         int accessibilityEnabled = 0; | ||||
|  | ||||
|         final String service = mContext.getPackageName() + "/com.mytest.accessibility.MyAccessibilityService"; | ||||
|         final String service = mContext.getPackageName() + "/" + BuildConfig.APPLICATION_ID + ".MyAccessibilityService"; | ||||
|  | ||||
|         boolean accessibilityFound = false; | ||||
|         try | ||||
|         { | ||||
|             accessibilityEnabled = Settings.Secure.getInt(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED); | ||||
|             Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled); | ||||
| //            Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled); | ||||
|         } | ||||
|         catch (Settings.SettingNotFoundException e) | ||||
|         { | ||||
|             Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage()); | ||||
| //            Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage()); | ||||
|         } | ||||
|         TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':'); | ||||
|  | ||||
|         if (accessibilityEnabled == 1) { | ||||
|             String settingValue = Settings.Secure.getString(mContext | ||||
|                             .getApplicationContext().getContentResolver(), | ||||
|                     Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); | ||||
|             if (settingValue != null) { | ||||
|         if (accessibilityEnabled == 1) | ||||
|         { | ||||
|             String settingValue = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); | ||||
|             if (settingValue != null) | ||||
|             { | ||||
|                 TextUtils.SimpleStringSplitter splitter = mStringColonSplitter; | ||||
|                 splitter.setString(settingValue); | ||||
|                 while (splitter.hasNext()) { | ||||
|                     String accessabilityService = splitter.next(); | ||||
|                 while (splitter.hasNext()) | ||||
|                 { | ||||
|                     String accessibilityService = splitter.next(); | ||||
|  | ||||
|                     if (accessabilityService.equalsIgnoreCase(service)) { | ||||
|                     if (accessibilityService.equalsIgnoreCase(service)) | ||||
|                     { | ||||
|                         return true; | ||||
|                     } | ||||
|                 } | ||||
| @@ -1026,7 +1028,9 @@ public class ActivityPermissions extends Activity | ||||
|                 usingElements.add(getResources().getString(R.string.queryAllPackages)); | ||||
|                 break; | ||||
|             case Manifest.permission.BIND_ACCESSIBILITY_SERVICE: | ||||
|                 usingElements.add(getResources().getString(R.string.bindAccessibilityService)); | ||||
|                 for(String ruleName : getRulesUsing(Action.Action_Enum.takeScreenshot)) | ||||
|                     usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); | ||||
|                 break; | ||||
|         } | ||||
|  | ||||
|         return usingElements; | ||||
| @@ -1035,6 +1039,15 @@ public class ActivityPermissions extends Activity | ||||
|     @Override | ||||
|     protected void onActivityResult(int requestCode, int resultCode, Intent data) | ||||
|     { | ||||
|         /* | ||||
|             All of the following permissions need to be "manually" activated by the user in some | ||||
|             buried system menu. | ||||
|             In my opinion by mistake the function will be called when the user has just landed | ||||
|             on one of those screens, not when he exits it again. To compensate for that onResume() | ||||
|             is overridden. This enables the permission screen to automatically close after all | ||||
|             required permissions have been granted. | ||||
|          */ | ||||
|  | ||||
|         super.onActivityResult(requestCode, resultCode, data); | ||||
|  | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) | ||||
| @@ -1665,4 +1678,19 @@ public class ActivityPermissions extends Activity | ||||
|             return false; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void onResume() | ||||
|     { | ||||
|         super.onResume(); | ||||
|  | ||||
|         for(String p : getRequiredPermissions(false)) | ||||
|         { | ||||
|             if(!havePermission(p, this)) | ||||
|                 return; | ||||
|         } | ||||
|  | ||||
|         // have all | ||||
|         setHaveAllPermissions(); | ||||
|     } | ||||
| } | ||||
| @@ -1,8 +1,14 @@ | ||||
| package com.jens.automation2; | ||||
|  | ||||
| import android.accessibilityservice.AccessibilityService; | ||||
| import android.os.Build; | ||||
| import android.util.Log; | ||||
| import android.view.Display; | ||||
| import android.view.accessibility.AccessibilityEvent; | ||||
|  | ||||
| import androidx.annotation.NonNull; | ||||
| import androidx.annotation.RequiresApi; | ||||
|  | ||||
| public class MyAccessibilityService extends AccessibilityService | ||||
| { | ||||
|     static MyAccessibilityService instance; | ||||
| @@ -10,7 +16,9 @@ public class MyAccessibilityService extends AccessibilityService | ||||
|     public static MyAccessibilityService getInstance() | ||||
|     { | ||||
|         if(instance == null) | ||||
|         { | ||||
|             instance = new MyAccessibilityService(); | ||||
|         } | ||||
|  | ||||
|         return instance; | ||||
|     } | ||||
| @@ -26,4 +34,18 @@ public class MyAccessibilityService extends AccessibilityService | ||||
|     { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onCreate() | ||||
|     { | ||||
|         super.onCreate(); | ||||
|         instance = this; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void onServiceConnected() | ||||
|     { | ||||
|         super.onServiceConnected(); | ||||
|         Miscellaneous.logEvent("i", "Accessibility service", "Service started.", 4); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								app/src/main/res/drawable-hdpi/copier.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								app/src/main/res/drawable-hdpi/copier.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 1.7 KiB | 
| @@ -893,6 +893,8 @@ | ||||
|     <string name="methodGet" translatable="false">GET</string> | ||||
|     <string name="methodPost" translatable="false">POST</string> | ||||
|     <string name="takeScreenshot">Take screenshot</string> | ||||
|     <string name="android.permission.BIND_ACCESSIBILITY_SERVICE">Bind to accessibility service</string> | ||||
|     <string name="bindAccessibilityService">Bind to accessibility service</string> | ||||
|     <string name="accessibilityApiPermissionHint">After clicking OK you\'ll be sent to a system dialog. Please select Automation there and allow "Allow accessibility API".</string> | ||||
|     <string name="accessibility_service_explanation">Required for certains actions.</string> | ||||
| </resources> | ||||
							
								
								
									
										12
									
								
								app/src/main/res/xml/config_accessibility_service.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/src/main/res/xml/config_accessibility_service.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <accessibility-service xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:accessibilityEventTypes="typeAllMask" | ||||
|     android:accessibilityFlags="flagDefault" | ||||
|     android:accessibilityFeedbackType="feedbackSpoken" | ||||
|     android:canPerformGestures="false" | ||||
|     android:canRequestFilterKeyEvents="false" | ||||
|     android:canRequestFingerprintGestures="false" | ||||
|     android:canRetrieveWindowContent="false" | ||||
|     android:canTakeScreenshot="true" | ||||
|     android:notificationTimeout="0" | ||||
|     android:description="@string/accessibility_service_explanation" /> | ||||
| @@ -1,3 +1,4 @@ | ||||
| * Fixed: Overlay permission for start other program action only required if startByActivity() is selected | ||||
| * Fixed: Broadcast receiver trigger would not trigger anything, but crash | ||||
| * Added: One can now choose between GET and POST when using triggerURL action | ||||
| * Added: One can now choose between GET and POST when using triggerURL action | ||||
| * Added: new action -> take screenshot | ||||
		Reference in New Issue
	
	Block a user