我正在尝试在长按按钮时共享声音文件。这是我的代码:
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,但是它给了我同样的问题。我做错了什么?
答案 0 :(得分:0)
您是否尝试在setType
之后设置主题和文字 intent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Email Message Body");
intent.putExtra(Intent.EXTRA_EMAIL,new String[] { "sendTo@gmail.com" });