[英]My soundboard app can't share .mp3 files
我是Java和Android编程的新手,正在开发音板应用程序。 目前,当您单击按钮时,应用程序会播放声音,但是我还想为每种声音添加共享功能(使用OnLongClick),但是我无法使其正常工作。 在过去的两天里,我一直在通过Internet寻找解决方案,但我无法解决。
我正在使用shareIntent,当用户长按该按钮时,它将显示一个您可以共享声音的应用程序列表(下拉框,蓝牙,whatsapp ...)。 如果我选择保管箱,它只会上传没有扩展名的文件,并且无法与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;
}
};
在清单中声明意图过滤器
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="audio/*" />
</intent-filter>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.