This is a part of my college project which I have to complete.In this project app i am sending whats app message automatically by using Accessibility feature of android through following java code.
numberlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
try {
Toast.makeText(getBaseContext(), (String) numberlist.getItemAtPosition(i), Toast.LENGTH_SHORT).show();
txtnumber.setText(numberlist.getItemAtPosition(i).toString());
PackageManager packageManager = MainActivity.this.getPackageManager();
Intent saif = new Intent(Intent.ACTION_VIEW);
String message;
message = txtmessage.getText().toString() + suffix.toString();
saif.setData(Uri.parse(url));
if (saif.resolveActivity(packageManager) != null) {
MainActivity.this.startActivityForResult(saif, 1);
}
} catch (Exception e) {
Log.e("ERROR WHATSAPP",e.toString());
Toast.makeText(getApplicationContext(),
"Contact not found",
Toast.LENGTH_LONG).show();
}
}
});
If the user's mobile number is created in the WhatsApp app, the message goes easily. If there is a mobile number on which WhatsApp is not created, then the following message appears.

I have using following Accessibility node info ....
List<AccessibilityNodeInfoCompat> sendMessageNodeInfoList = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.whatsapp:id/send");
String actname = event.getClassName().toString();
switch (actname) {
case "com.whatsapp.Conversation":
sendMessageNodeInfoList = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.whatsapp:id/send");
if (sendMessageNodeInfoList.size() > 0) {
sendMessageNodeInfoList.get(0).performAction(ACTION_CLICK);
}
break;
case "com.whatsapp.HomeActivity":
sendNext();
break;
case "com.whatsapp.contact.picker.ContactPicker":
Toast.makeText(this, "Unable to find contacts in your list! Skipping!!!", Toast.LENGTH_SHORT).show();
performGlobalAction(GLOBAL_ACTION_BACK);
break;
}
assert sendMessageNodeInfoList != null;
AccessibilityNodeInfoCompat sendMessageButton = sendMessageNodeInfoList.get(0);
if (!sendMessageButton.isVisibleToUser()) {
return;
}
sendMessageButton.performAction(ACTION_CLICK);
My question is, how can we close this notification by auto clicking on the OK or Cancel button using the accessibility feature of Android? I want that when a Whats App message is sent to a user's mobile number, it should first be checked whether his mobile number is available on Whats App or not. If Whats App is created on the mobile number, then a message should be sent to him and if Whats App is not created on his mobile number, then auto-click on this pop-up notification to close it and return to the main screen. This is the last project of my college which I have to complete please help me to complete it. Thanks
I have solved this issue with following code: Someone has truly said that " Try Try again ".