我試着這樣說:如何在Android Studio中將聲音分享給whatsapp?
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的告訴我再試一次。
我也發現了這種方式在this stackoverflow question答案:
String sharePath = Environment.getExternalStorageDirectory().getPath()
+ "/Soundboard/Ringtones/custom_ringtone.ogg";
Uri uri = Uri.parse(sharePath);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Sound File"));
我有什麼,而不是寫這在我的情況?:
Environment.getExternalStorageDirectory().getPath()
+ "/Soundboard/Ringtones/custom_ringtone.ogg"
我sound.mp3文件位於在原始文件夾中
哪裏是你的音頻文件在什麼位置? – jagapathi
@jagapathi在原始文件夾 – PentaGames