I created an Android Application.
and I want to send an image on Whatsapp, In Background. I came to know it can only be done by Accessibility API's.
I was able to send the Text ( Thanx to : https://stackoverflow.com/a/71804457/5323184 ) , but for image. I am unable to
I followed a similar approach for images : But its not sending it automatically.
AccessibilityServiceManager serviceManager = new AccessibilityServiceManager(activity.mContext);
if (serviceManager.hasAccessibilityServicePermission(WhatsAppAccessibilityServices.class)) {
File appFolderLocation = new File(cachePath, OUTPUT_RENT_RECEIPT_PNG_NAME);
Uri contentUri = FileProvider.getUriForFile(activity.mContext, BuildConfig.APPLICATION_ID.concat(".provider"), appFolderLocation);
if (contentUri == null) {
In_Place.toastHelper.toastErrorMsg("File Not Present");
} else {
String toNumber = getFormattedNumber(activity.getTenantContactNumber());
toNumber = toNumber.replace("+", "").replace(" ", ""); // E164 format without '+' sign
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, caption);
sendIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
sendIntent.setDataAndType(contentUri, activity.mContext.getContentResolver().getType(contentUri));
sendIntent.putExtra("jid", toNumber + "@s.whatsapp.net"); //phone number without "+" prefix
sendIntent.setPackage(packageName); //com.whatsapp //com.whatsapp.w4b
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.mContext.startActivity(sendIntent);
}
} else {
serviceManager.requestUserForAccessibilityService((Activity) activity.mContext);
}