【问题标题】:how to send image or video to whatsapp status in android programmatically?如何以编程方式将图像或视频发送到android中的whatsapp状态?
【发布时间】:2019-01-31 20:56:23
【问题描述】:

如何将图像或视频发送到 android 中的 WhatsApp 状态(或故事)。

我们可以通过以下方式将图片发送给联系人:

Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.putExtra(Intent.EXTRA_STREAM, imageURI);
sendIntent.putExtra("jid", "91"+mobile + "@s.whatsapp.net");
sendIntent.putExtra(Intent.EXTRA_TEXT, "whatsapp image caption");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setPackage("com.whatsapp");
sendIntent.setType("image/*");

但是如何将它发送到我的whatsapp状态?

【问题讨论】:

  • 你得到答案了吗?,TikTok的应用程序能够显示一个选项来分享它bt WhatsApp状态,IDK他们是怎么做到的

标签: android whatsapp share-intent


【解决方案1】:
private void shareToWhatsApp() {
    String type = "video/*";

    // Create the new Intent using the 'Send' action.
    Intent share = new Intent(Intent.ACTION_SEND);

    // Set the MIME type
    share.setType(type);

    // Create the URI from the media
    Uri uri = FileProvider.getUriForFile(DetailActivity.this, getString(R.string.authority), file);
    share.setPackage("com.whatsapp");
    // Add the URI to the Intent.
    share.putExtra(Intent.EXTRA_STREAM, uri);
    share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    PackageManager packageManager = getPackageManager();
    if (share.resolveActivity(packageManager) != null) {
        startActivity(share);
        startActivity(Intent.createChooser(share, "Share to"));

    } else {
        alertForApp(getString(R.string.install_whatsapp), "com.whatsapp");
    }

    // Broadcast the Intent.
}

【讨论】:

  • //packagename//.fileProvider
  • 你能详细说明一下代码是如何解决问题的吗?您是否也可以通过编辑将代码添加到答案中,而不是添加 cmets?
猜你喜欢
  • 1970-01-01
  • 2020-07-11
  • 1970-01-01
  • 2014-06-29
  • 1970-01-01
  • 2018-04-16
  • 2014-05-12
  • 2015-02-20
  • 2014-09-06
相关资源
最近更新 更多