我正在使用图片和文字通过意图分享whatsapp和其他电子邮件和短信。
但是whatsapp中的问题是,图像正在显示,文本也显示但是url没有显示为链接。它显示为普通文本。您可以按以下方式查看以下代码。
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.\n\n" +
"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();
}
答案 0 :(得分:0)
如果您想共享网址,通常会这样做:
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