簡體   English   中英

如何將音頻文件從原始文件夾共享到社交應用程序?

[英]How to share audio file from raw folder into social apps?

我想向我的音板應用程序添加共享選項,現在我從原始文件夾中獲取音頻文件時遇到問題。

我正在嘗試使用該代碼進行共享功能:

 public void onClick(View v){
                String sharePath = Environment.getExternalStorageDirectory().getPath()
                        + "/res/raw/sound1.mp3";
                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"));
            }

但是Messenger和其他應用程序在從我的應用程序獲取音頻文件時遇到問題。 我是否應該先編寫腳本以將音頻保存在手機存儲中,然后使用該文件在其他應用程序中共享?

資源是開發機器上的文件。 它們不是設備文件系統上的文件。

我是否應該先編寫腳本以將音頻保存在手機存儲中,然后使用該文件在其他應用程序中共享?

將資源復制到內部存儲的某個位置(例如getCacheDir() ),並設置FileProvider以允許您共享內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM