0
我是新来的Java和Android编程,我正在制作一个音板应用程序。 当你点击一个按钮时,应用程序播放声音,但我也想为每个声音添加共享功能(使用OnLongClick),但我无法使其工作。 过去两天我一直在寻找通过互联网的解决方案,但我无法解决它。我的音板应用程序无法共享.mp3文件
我使用的是shareIntent,当用户长时间点击按钮时,它会显示一个可以共享声音的应用程序列表(Dropbox,蓝牙,WhatsApp ...)。 如果我选择了dropbox,它只是上传一个没有扩展名的文件,与Whatsapp共享将无法工作,并会显示此错误:“无法发送,请重试”。
我的代码如下所示:
final int[] buttonIds = { R.id.sound01, R.id.sound02, R.id.sound03,
R.id.sound04, R.id.sound05, R.id.sound06,
R.id.sound07, R.id.sound08, R.id.sound09,
R.id.sound10, R.id.sound11, R.id.sound12 };
final int[] soundIds = { R.raw.sound01, R.raw.sound02, R.raw.sound03,
R.raw.sound04, R.raw.sound05, R.raw.sound06,
R.raw.sound07, R.raw.sound08, R.raw.sound09,
R.raw.sound10, R.raw.sound11, R.raw.sound12 };
View.OnLongClickListener listener2 = new View.OnLongClickListener()
{
@Override
public boolean onLongClick(View v)
{
for(int i = 0; i < buttonIds.length; i++)
{
if(v.getId() == buttonIds[i])
{
selectedSoundId = soundIds[i];
// Can't share audio. It shares it with no format, so whatsapp won't accept it
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("audio/mp3");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://com.guillefix.zombie_soundboard/" + selectedSoundId));
startActivity(Intent.createChooser(shareIntent, "Send to:"));
break;
}
}
return false;
}
};
没有工作,文件仍没有扩展。 – guillefix 2015-02-06 21:05:04
是的它不会。我只记得你不能将任何图像或音频直接发送到WhatsApp。在你的情况下,你首先必须将该音频作为**文件**保存到内部存储器,然后将该文件发送到WhatsApp 选中此链接(http://stackoverflow.com/questions/16352081/android -saving-the-audio-files-into-internal-storage)它会帮助你。 – zackygaurav 2015-02-07 20:32:46