【发布时间】:2015-11-01 08:42:42
【问题描述】:
我正在尝试在长按按钮时共享声音文件。这是我的代码:
public class Tab2 extends Fragment{
Button button1;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.tab_2,container,false);
button1 = (Button) v.findViewById(R.id.button1);
button1.setLongClickable(true);
button1.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
Uri uri = Uri.parse("android.resource://test.testapp/raw/" + R.raw.sound1);
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Deel geluidje"));
return true;
}
});
return v;
}
}
但是,当我长按按钮时,会出现分享菜单,但我只能与 WhatsApp 分享声音。任何其他应用程序都不起作用。 (Gmail 给我一条消息说''无法附加空文件''。声音是 .ogg 格式,我尝试将其转换为 .wav,但它给了我同样的问题。我做错了什么?
【问题讨论】: