网址未显示在whatsapp android中



我正在使用图像和文本通过意图在whatsapp和其他电子邮件和短信中共享。

但是whatsapp的问题是,图像正在显示,文本也显示,但网址没有显示为链接。它显示为普通文本。您可以看到以下代码,如下所示。

Uri imageUri = Uri.parse(photoFile.getAbsolutePath()); //getting image 
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
//Target whatsapp:
shareIntent.setPackage("com.whatsapp");
//Add text and then Image URI
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Sharing the details.nn" +
"QR Code:" + QRCode + "n" +
"Nama Retailer:" + retailerName + "n" +
"Nama Owner:" + ownerName + "n" +
"Nomer TRX:" + normorTrx + "n" +
"Disclaimer" + "n" +
"Please use the below link" + " "+
"http://116.12.2/images/disclaimer/NG20_SaTria_TC_Legal_050418_DISCLAIMER.pdf" +" "+
"for further information."
);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
if (shareIntent.resolveActivity(getPackageManager()) != null) {
startActivity(shareIntent);
} else {
Toast.makeText(RetailerQRCodeGenerationActivity.this, "not available", Toast.LENGTH_SHORT).show();
}
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(RetailerQRCodeGenerationActivity.this, "Application not available.", Toast.LENGTH_SHORT).show();
}

当你想分享一个网址时,你通常会这样做:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
i=intent.putExtra(Intent.EXTRA_TEXT, "http://www.url.com");

但是您想共享两种不同类型的意图,因为我在您的代码中看到您正在使用shareIntent.setType("image/jpeg");

两个共享不同类型的元素,您需要使用多个 MIME 类型,如下所示:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
String[] mimeTypes = {"image/*", "text/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);

有关更多详细信息,请查看:https://developer.android.com/guide/topics/providers/content-provider-basics#MIMETypeReference

相关内容

  • 没有找到相关文章

最新更新