2012-02-25 50 views
1

我已经通过这个代码做了录音:Android:如何发送语音作为MMS附件?

recorder = new MediaRecorder(); 
     recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
     recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
     recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
     recorder.setOutputFile(Environment 
       .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) 
       +"test.3gp"); 
     try { 
      recorder.prepare(); 
     } catch (IOException io) { 

      Toast.makeText(getApplicationContext(), "Record File", Toast.LENGTH_LONG).show(); 

     } 
     recorder.start(); 

,并尝试使用份额的意图像这样分享:

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 

     sharingIntent.setType("video/3gp"); 

      sharingIntent.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/Downloadtest.3gp"); 

     startActivity(Intent.createChooser(sharingIntent, "Share via")); 

但是当我的邮箱是设置它通过电子邮件发送,但我想分享它vaia mms?它正在以毫米为单位?怎么做?

+0

@NNirupoma Saha Chaiti接受的答案是你的工作。你必须在htc device.i有htc一个不能附加文件测试。 – Harshid 2013-01-11 11:43:32

+0

我在做类似的事情! http://stackoverflow.com/questions/14452808/sending-and-receiving-mms-in-android – toobsco42 2013-01-22 06:45:34

回答

4

你可以试试这个在我的情况下,它的工作完美。

Intent sendIntent = new Intent(Intent.ACTION_SEND); 
       sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity"); 
       sendIntent.putExtra("address", "9999999999"); 
       sendIntent.putExtra("sms_body", "if you are sending text"); 
       final File file1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"Downloadtest.3gp"); 
       Uri uri = Uri.fromFile(file1); 
       Log.e("Path", "" + uri); 
       sendIntent.putExtra(Intent.EXTRA_STREAM, uri); 
       sendIntent.setType("video/3gp"); 
       startActivity(sendIntent); 

但有些设备不能接受像HTC渴望,HTC之一,lava.In你的情况下,工作完美然后粘贴代码。

0

请尝试以下代码,

Intent sendIntent = new Intent(Intent.ACTION_SEND); 
sendIntent.putExtra("sms_body", "some text"); 
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url)); 
sendIntent.setType("audio/3gp"); 
+0

但我在这里attatching音频,它会工作吗? – 2012-02-25 06:05:28

+0

是,在url变量,设置您的音频文件 – Android 2012-02-25 06:11:51

+1

的我也一样ü说的路径,但没有工作:( 其说 抱歉,你不能在你的信息添加图片? 有没有什么具体的文件格式? – 2012-02-25 06:20:13