Java 如何在Android Studio中与whatsapp共享声音?
我这样试过:Java 如何在Android Studio中与whatsapp共享声音?,java,android,audio,resources,share,Java,Android,Audio,Resources,Share,我这样试过: shareBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent
shareBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("audio/mp3");
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://com.example.aaron.sharetest/sound.mp3"));
startActivity(Intent.createChooser(shareIntent, "Sound shared!"));
但这不起作用,whatsapp让我再试一次
我在以下问题的答案中也发现了这一点:
在我的情况下,我需要写什么来代替这个
Environment.getExternalStorageDirectory().getPath()
+ "/Soundboard/Ringtones/custom_ringtone.ogg"
My sound.mp3文件位于原始文件夹中您可以使用此代码共享原始文件夹文件 名称=文件名
你的音频文件在哪里?@jagapathi在原始文件夹中,如果我单击whatsapp,它仍然会显示“共享失败,请重试”检查它,当我找到sol时告诉你
Environment.getExternalStorageDirectory().getPath()
+ "/Soundboard/Ringtones/custom_ringtone.ogg"
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
share.setType("audio/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(
"android.resource://"+ this.getPackageName()+"/raw/" + name
));
startActivity(Intent.createChooser(sharingIntent, "Share via"));