here is the code through which i am sharing my image or video from an adaptor to WhatsApp it was working fine but now just the toast is shown that whats app not install is there any issue in the code am I missing something?
public void shareWhatsapp(String type, String path, String package_name) {
Uri uri = FileProvider.getUriForFile(mFragment, BuildConfig.APPLICATION_ID + ".provider", new File(path));
PackageManager pm = mFragment.getPackageManager();
try {
PackageInfo info = pm.getPackageInfo(package_name, PackageManager.GET_META_DATA);
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sharingIntent.setType(type);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.setPackage(package_name);
mFragment.startActivity(Intent.createChooser(sharingIntent, "Share via"));
} catch (PackageManager.NameNotFoundException e) {
Toast.makeText(mFragment, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
here is the listener
holder.repostWhatsapp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ModelStatus curVideo = getItem(position);
if (curVideo.getFull_path().endsWith(".jpg")) {
shareWhatsapp("image/jpg", curVideo.getFull_path(), "com.whatsapp");
} else if (curVideo.getFull_path().endsWith(".mp4")) {
shareWhatsapp("video/mp4", curVideo.getFull_path(), "com.whatsapp");
}
}
});