【问题标题】:Url not displaying in whatsapp android网址未在whatsapp android中显示
【发布时间】:2018-05-07 04:03:52
【问题描述】:

我正在使用图像和文本通过意图在 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();
                }

【问题讨论】:

  • 我可以知道为什么它被否决了吗?

标签: android android-intent android-pendingintent


【解决方案1】:

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

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

【讨论】:

  • 谢谢。让我检查一下。
猜你喜欢
  • 2019-05-10
  • 1970-01-01
  • 2022-11-10
  • 1970-01-01
  • 2020-01-10
  • 1970-01-01
  • 1970-01-01
  • 2018-04-30
  • 2016-03-16
相关资源
最近更新 更多