Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 共享音频文件仅适用于某些应用程序_Java_Android_Libgdx - Fatal编程技术网

Java 共享音频文件仅适用于某些应用程序

Java 共享音频文件仅适用于某些应用程序,java,android,libgdx,Java,Android,Libgdx,看来我得了虫子。至少我认为这是一个错误。我编写了一种音板,希望增加与他人共享声音的功能。我要共享的代码如下: public void share(Sound sound) { //libgdx command to copy an internal file(classpath) to external memory //sound.file is the relative path to the audio file that will be shared Gdx.fi

看来我得了虫子。至少我认为这是一个错误。我编写了一种音板,希望增加与他人共享声音的功能。我要共享的代码如下:

public void share(Sound sound) {
    //libgdx command to copy an internal file(classpath) to external memory
    //sound.file is the relative path to the audio file that will be shared
    Gdx.files.internal(sound.file).copyTo(Gdx.files.external("/skrelpoid/KJ/share/" + sound.file));
    String sharePath = Environment.getExternalStorageDirectory().getPath() + "/skrelpoid/KJ/share/" + sound.file;
    Uri uri = Uri.parse(sharePath);
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
    sendIntent.setType("audio/*");
    //app is the main application
    app.startActivity(Intent.createChooser(sendIntent, "Teile den Sound"));
}

我的问题是,这是可行的,但只适用于某些应用程序。例如,当我与WhatsApp或DropBox共享音频时,它似乎工作得非常好,但当我尝试使用Google Drive或Bluetooth执行相同操作时,似乎出现了一些错误。请注意,音频的文件类型是WAV。我还确保我有权限写入外部存储器,但仍然只有一些应用程序可以工作。我真的很迷茫,如果有人能帮助我,我将不胜感激。

似乎错误是因为
Uri.parse(str)
。 以下代码(取自)似乎有效:

public void share(Sound sound) {
    Gdx.files.internal(sound.file).copyTo(Gdx.files.external("/skrelpoid/KJ/share/" + sound.file));
    File file = new File(Environment.getExternalStorageDirectory().getPath() + "/skrelpoid/KJ/share/" + sound.file);
    Uri uri = Uri.fromFile(file);
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
    sendIntent.setType(MimeTypeMap.getSingleton().getMimeTypeFromExtension(sound.getExtension()));
    app.startActivity(Intent.createChooser(sendIntent, "Teile den Sound"));
}

“请注意,音频的文件类型是WAV”--然后将MIME类型用于WAV。使用
MimeTypeMap
查找它,因为似乎有几种可能的MIME类型。就目前而言,接收者不知道文件格式是什么。我不明白这会有什么帮助,例如Google Drive知道它正在上传的文件类型。为什么它甚至需要知道,它只是上传它