2017-06-22 170 views
0

我試着這樣說:如何在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文件位於在原始文件夾中

+0

哪裏是你的音頻文件在什麼位置? – jagapathi

+0

@jagapathi在原始文件夾 – PentaGames

回答

0

您可以使用此代碼共享原始文件夾文件

=文件名

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")); 
+0

如果我點擊whatsapp它仍然說「共享失敗,請重試」 – PentaGames

+0

檢查它讓你知道我什麼時候找到溶膠 – jagapathi

相關問題