我试图通过whatsapp或任何其他信使应用程序发送/共享mp3原始文件。

时间:2017-05-05 05:41:40

标签: java android

public void share(String song){

    Uri uri = Uri.parse("android.resource://com.dsbsoft.myApp/raw/"+song+".mp3");

    Intent share = new Intent(Intent.ACTION_SEND);
    share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    share.setType("audio/mp3");
    share.putExtra(Intent.EXTRA_STREAM, uri);

    this.startActivity(Intent.createChooser(share, "Send song"));
}

一切都很完美,但在发送文件的时候,我认为,它不存在...... 在void中来自String变量歌曲,其中包含文件名。 例如: 电话是:分享(" abc");我想发送mp3文件(它在原始文件夹中)abc.mp3

2 个答案:

答案 0 :(得分:0)

试试这个:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://www.bootstraptoggle.com/js/bootstrap-toggle.js"></script>
<fieldset id='demo1' class="rating">
  <input class="stars" type="radio" id="1star_a-5" name="1rating" value="5" />
  <label class="full" for="1star_a-5" title="Awesome - 5 stars"></label>
  <input class="stars" type="radio" id="1star_a_5-half" name="1rating" value="4.5" />
  <label class="half" for="1star_a_5-half" title="Pretty good - 4.5 stars"></label>
  <input class="stars" type="radio" id="1star_a-4" name="1rating" value="4" />
  <label class="full" for="1star_a-4" title="Pretty good - 4 stars"></label>
  <input class="stars" type="radio" id="1star_a_4-half" name="1rating" value="3.5" />
  <label class="half" for="1star_a_4-half" title="Meh - 3.5 stars"></label>
  <input class="stars" type="radio" id="1star_a-3" name="1rating" value="3" />
  <label class="full" for="1star_a-3" title="Meh - 3 stars"></label>
  <input class="stars" type="radio" id="1star_a_3-half" name="1rating" value="2.5" />
  <label class="half" for="1star_a-3-half" title="Kinda bad - 2.5 stars"></label>
  <input class="stars" type="radio" id="1star2" name="1rating" value="2" />
  <label class="full" for="1star2" title="Kinda bad - 2 stars"></label>
  <input class="stars" type="radio" id="1star2half" name="1rating" value="1.5" />
  <label class="half" for="1star2half" title="Meh - 1.5 stars"></label>
  <input class="stars" type="radio" id="1star1" name="1rating" value="1" />
  <label class="full" for="1star1" title="Sucks big time - 1 star"></label>
  <input class="stars" type="radio" id="1starhalf" name="rating" value="0.5" />
  <label class="half" for="1starhalf" title="Sucks big time - 0.5 stars"></label>
</fieldset>

</div>
<br><br><br>
<strong>2. Productivity </strong>- the extent to which the employee's behaviors are directed toward fostering positive working relationships in a diverse workplace, respect for one's fellow workers, and cooperation with students, customers, and visitors.
</p>



<div class="form-group">
  <label for="comment">Comments:
                        :</label>
  <textarea class="form-control" rows="5" id="comment"></textarea>
</div>
<div class="form-group">
  <fieldset id='demo2' class="rating">
    <input class="stars" type="radio" id="2star_a-5" name="2rating" value="5" />
    <label class="full" for="2star_a-5" title="Awesome - 5 stars"></label>
    <input class="stars" type="radio" id="2star_a_5-half" name="2rating" value="4.5" />
    <label class="half" for="2star_a_5-half" title="Pretty good - 4.5 stars"></label>
    <input class="stars" type="radio" id="2star_a-4" name="2rating" value="4" />
    <label class="full" for="2star_a-4" title="Pretty good - 4 stars"></label>
    <input class="stars" type="radio" id="2star_a_4-half" name="2rating" value="3.5" />
    <label class="half" for="2star_a_4-half" title="Meh - 3.5 stars"></label>
    <input class="stars" type="radio" id="2star_a-3" name="2rating" value="3" />
    <label class="full" for="2star_a-3" title="Meh - 3 stars"></label>
    <input class="stars" type="radio" id="2star_a_3-half" name="2rating" value="2.5" />
    <label class="half" for="2star_a-3-half" title="Kinda bad - 2.5 stars"></label>
    <input class="stars" type="radio" id="2star2" name="2rating" value="2" />
    <label class="full" for="2star2" title="Kinda bad - 2 stars"></label>
    <input class="stars" type="radio" id="2star2half" name="2rating" value="1.5" />
    <label class="half" for="2star2half" title="Meh - 1.5 stars"></label>
    <input class="stars" type="radio" id="2star1" name="2rating" value="1" />
    <label class="full" for="2star1" title="Sucks big time - 1 star"></label>
    <input class="stars" type="radio" id="2starhalf" name="2rating" value="0.5" />
    <label class="half" for="2starhalf" title="Sucks big time - 0.5 stars"></label>
  </fieldset>

</div>
<br><br><br>


<strong>3. Work Quality </strong> - the extent to which the employee contributes to the effectiveness of the department and the overall mission of the university. (NOTE: Time off approved under FMLA may not be considered) </p>


<div class="form-group">
  <label for="comment">Comments:
                        :</label>
  <textarea class="form-control" rows="5" id="comment"></textarea>
</div>

<div class="form-group">
  <fieldset id='demo3' class="rating">
    <input class="stars" type="radio" id="3star_a-5" name="3rating" value="5" />
    <label class="full" for="3star_a-5" title="Awesome - 5 stars"></label>
    <input class="stars" type="radio" id="3star_a_5-half" name="3rating" value="4.5" />
    <label class="half" for="3star_a_5-half" title="Pretty good - 4.5 stars"></label>
    <input class="stars" type="radio" id="3star_a-4" name="3rating" value="4" />
    <label class="full" for="3star_a-4" title="Pretty good - 4 stars"></label>
    <input class="stars" type="radio" id="3star_a_4-half" name="3rating" value="3.5" />
    <label class="half" for="3star_a_4-half" title="Meh - 3.5 stars"></label>
    <input class="stars" type="radio" id="3star_a-3" name="3rating" value="3" />
    <label class="full" for="3star_a-3" title="Meh - 3 stars"></label>
    <input class="stars" type="radio" id="3star_a_3-half" name="3rating" value="2.5" />
    <label class="half" for="3star_a-3-half" title="Kinda bad - 2.5 stars"></label>
    <input class="stars" type="radio" id="3star2" name="3rating" value="2" />
    <label class="full" for="3star2" title="Kinda bad - 2 stars"></label>
    <input class="stars" type="radio" id="3star2half" name="3rating" value="1.5" />
    <label class="half" for="3star2half" title="Meh - 1.5 stars"></label>
    <input class="stars" type="radio" id="3star1" name="3rating" value="1" />
    <label class="full" for="3star1" title="Sucks big time - 1 star"></label>
    <input class="stars" type="radio" id="3starhalf" name="3rating" value="0.5" />
    <label class="half" for="3starhalf" title="Sucks big time - 0.5 stars"></label>
  </fieldset>

</div>
<br><br><br>

答案 1 :(得分:0)

显然我们无法直接发送资源文件。 这就是为什么我做以下事情。 要发送mp3文件,我将其刻录在存储中的文件夹上并共享此新文件。

代码

public void makeOutSide(String song,InputStream ins){

    // Create the directory
    File dir = new File(Environment
            .getExternalStorageDirectory() + "/.CSOUNDS/");
    // If it does not exists, make it.
    if (!dir.exists()) {
        dir.mkdir(); // Generating the directory
    }
    try {
        // Open the resource
        byte[] buffer = new byte[ins.available()];
        ins.read(buffer);
        ins.close();
        // Burn
        String filename = Environment
                .getExternalStorageDirectory().toString()
                + "/.CSOUNDS/"+song+".mp3";
        FileOutputStream fos = new FileOutputStream(filename);
        fos.write(buffer);
        fos.close();
    } catch (Exception e) {
    }
}

public void share(String song, InputStream ins){
    makeOutSide(song,ins);
    String rout = Environment.getExternalStorageDirectory().toString()+"/.CSOUNDS/"+song+".mp3";
    Uri uri = Uri.parse(rout);
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("audio/*");
    share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    share.putExtra(Intent.EXTRA_STREAM,uri);
    startActivity(Intent.createChooser(share, "Share song"));
}

在share方法的调用中以这种方式输入一个InputStream: InputStream ins = getResources()。openRawResource(R.raw.abc);                 份额( “ABC”,INS);