visit
And think about that! How interesting the concept is! There is a difference between setting an alarm for yourself and getting reminded of stuff and someone texting you to remind you to do something. When a message is sent by a person, it has that special effect! So, I thought, why not use technology to intervene in human lives in a psychologically positive way?
I have used Accessibility Service for it.
What is Accessibility Service, you may ask?Accessibility services are a feature of the Android framework designed to provide alternative navigation feedback to the user on behalf of applications installed on Android devices. An accessibility service can communicate to the user on the application's behalf, for example by converting text to speech or providing haptic feedback when a user is hovering on an important area of the screen
Source:
I have used the Accessibility Service to create this automation for myself. The service enables us to not just view text but also, perform actions on the user's behalf. So, how can you create similar automation for yourself?Follow these steps:
1. Define the service and XML config:accessibility_service_config.xml
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="//schemas.android.com/apk/res/android"
android:packageNames="com.whatsapp"
android:accessibilityEventTypes="typeWindowStateChanged|typeWindowContentChanged"
android:accessibilityFlags="flagReportViewIds|flagRetrieveInteractiveWindows"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="1000"
android:canRetrieveWindowContent="true"
android:settingsActivity="infinite.hacks.aditi.autowhatsapp.ChatsAccService"/>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="//schemas.android.com/apk/res/android"
package="infinite.hacks.aditi.autowhatsapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".ChatsAccService"
android:enabled="true"
android:label="Automate Chats WhatsApp"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility_service_config" />
</service>
</application>
</manifest>
2. Define the Accessibility Service, extends AccessibilityService:
Reference: //developer.android.com/reference/android/accessibilityservice/AccessibilityService
3. Find out the IDs of UI elements that hold the:public void onAccessibilityEvent (AccessibilityEvent event) { ... }Get the root from the event nodes, traverse through the tree and find out the nodes having the above IDs acquired in step 3. Once you have the IDs, you can then use the method performAction to simulate sending the chats:
AccessibilityNodeInfo textBox = getNode(rootNode, chatBoxRefId);
Bundle arguments = new Bundle();
if (convIndex == convs.length -1) {
arguments.putString(AccessibilityNodeInfoCompat.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "<3");
} else {
arguments.putString(AccessibilityNodeInfoCompat.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, convs[convIndex % (convs.length - 1)]);
convIndex ++;
}
textBox.performAction(AccessibilityNodeInfoCompat.ACTION_SET_TEXT, arguments);
AccessibilityNodeInfo sendButton = getNode(rootNode, sendButtonRefId);
sendButton.performAction(AccessibilityNodeInfo.ACTION_CLICK);
If you want an already coded app, checkout:
Previously published at: //www.aditi.fyi/post/i-automated-my-whatsapp-chats