Aks*_*jar 7 android whatsapp share-intent
如何在 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/*");
Run Code Online (Sandbox Code Playgroud)
但如何将其发送到我的 Whatsapp 状态呢?
小智 -2
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.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4520 次 |
| 最近记录: |