Intent.ACTION_SEND WhatsApp的
问题描述:
我试着通过WhatsApp的共享MP3文件。它可以与其他应用程序(如Gmail)完美协作,但它可以在whatsapp上运行。谁能帮我?我需要添加一些putExtra()吗?Intent.ACTION_SEND WhatsApp的
这里是我的代码:
public void shareWithFriends(int id)
{
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/mp3");
//share.putExtra(Intent.EXTRA_SUBJECT,"subject");
//Uri uri = Uri.parse("android.resource://com.igs.pokemonsoundboard/" + id);
Uri uri = Uri.parse("android.resource://com.igs.pokemonsoundboard/raw/" + R.raw.pikachump3);
share.putExtra(Intent.EXTRA_STREAM,uri);
//share.putExtra("sms_body","Ringtone File :");
startActivity(Intent.createChooser(share, "Share sound"));
}
感谢;)
答
您应该复制您的音频文件到SD卡,并分享它的文件,而不是Android的资源,像这样:
final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("audio/mp3");
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://"+path+filename));
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_sound)));
现在它应该通过whatsapp。
答
尝试改变MIME类型 “音频/ MPEG3”,这样第二行显示
share.setType("audio/mpeg3")
+0
感谢onielse14,但它dosent工程。我尝试将类型更改为mpeg3,但没有成功。任何其他想法? – user1116665 2011-12-26 19:39:33
答
的WhatsApp也接受OGG格式:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("audio/ogg");
shareIntent.putExtra(Intent.EXTRA_STREAM, getSoundUri());
startActivity(shareIntent);
答
你必须在你的代码包括此:
sendIntent.setPackage("com.whatsapp");
此代码不适用于我,即使我已将该文件保存在“sdcard”中,但我收到'无法发送,请重试'消息 – 2014-12-17 11:19:20