`Below is the code i am taking SS and then sharing i get the correct path where SS is installing but facing error to share it on a whats app number directly though Intent.Chooser
public void shareScreenshot(File file, String phoneNumber) {
try {
Uri uri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".fileprovider", file);
// Create the intent to open the chat in WhatsApp Business
Log.w("jarvis", "filepath" + uri.getEncodedPath());
String whatsappInstalledPackage = isPackageExisted("com.whatsapp");
Intent openChatIntent = new Intent(Intent.ACTION_VIEW);
openChatIntent.setData(Uri.parse("https://wa.me/" + phoneNumber));
openChatIntent.setPackage(whatsappInstalledPackage);
// Create the intent to share the screenshot
Intent shareScreenshotIntent = new Intent(Intent.ACTION_SEND);
shareScreenshotIntent.setType("image/png");
shareScreenshotIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareScreenshotIntent.putExtra("jid", phoneNumber + "@s.whatsapp.net");
shareScreenshotIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareScreenshotIntent.setPackage(whatsappInstalledPackage);
Log.w("jarvis", "check first done");
startActivity(openChatIntent);
finish();
new Handler(Looper.getMainLooper()).postDelayed(()->{
shareScreenshotIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(shareScreenshotIntent, "SS"));
finish();
}, 2000);
} catch (Exception e) {
Log.e("ShareScreenshot", "Failure: " + e.getMessage());
showToast("Error sharing screenshot");
}
}
1