使用intent android通过短信发送音频

时间:2011-12-19 18:15:04

标签: android mms

我是Android新手。我正在尝试发送带有m4a格式(或其他,如AMR或3GP)的音频文件的彩信。要做到这一点,我使用一个意图,但它永远不会发送我的彩信。这是我正在使用的代码:

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/m4a");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + new Environment.getExternalStorageDirectory().getPath()+"/recordaudio.m4a")));
startActivity(share);

我的音频播放速度不超过30kb。 请问你能帮帮我吗 ? 对不起英语我是法国人

File audiofile = new File(directory,"/recordaudio.m4a");                                        
byte     fileContent[] = new byte[(int) audiofile.length()];                                            
InputStream input = new FileInputStream(audiofile);    

int data = input.read();                                        
while(data != -1) {                                           
    data = input.read(fileContent);                                     
}
input.close();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_PHONE_NUMBER, mPhoneNumber);
sendIntent.setType("audio/*");
sendIntent.putExtra(Intent.EXTRA_STREAM, fileContent);
startActivity(sendIntent);*

首先,非常感谢你的帮助!!!! 我试过这个代码而mms不发送... 你能帮帮我吗?

1 个答案:

答案 0 :(得分:1)

您发送的是音频文件的Uri,但不是音频文件本身。

在意图

中发送音频文件不是一个好主意

如果您仍希望发送音频文件的byte []在intent中 - 使用InputStream从给定URI下载这些字节后