1. Download our Official Android App: Forums for Android!

Apps Intent Audio Recording

Discussion in 'Android Development' started by sam.almighty85, Aug 2, 2011.

  1. sam.almighty85

    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Aug 2, 2011

    Aug 2, 2011
    1
    0
    5
    Hello All,

    I am new to this forum. I am trying to invoke the default audio recorder using intents. I start intent using the startActivityForResult after the recording is complete my activity result always results 0 (which is Activity.RESULT_CANCELED) and my intent is null. My code is as below:
    Code (Text):
    1.  
    2. package com.abc.audiointent;
    3.  
    4. import android.app.Activity;
    5. import android.content.Intent;
    6. import android.net.Uri;
    7. import android.os.Bundle;
    8. import android.provider.MediaStore;
    9. import android.view.View;
    10. import android.view.View.OnClickListener;
    11. import android.widget.Button;
    12. import android.widget.LinearLayout;
    13.  
    14. public class AudioActivity extends Activity implements OnClickListener {
    15.     /** Called when the activity is first created. */
    16.     private Button sampleButton;
    17.     @Override
    18.     public void onCreate(Bundle savedInstanceState) {
    19.         super.onCreate(savedInstanceState);
    20.         LinearLayout finalContainer=new LinearLayout(this);
    21.         sampleButton=new Button(this);
    22.         sampleButton.setOnClickListener(this);
    23.         sampleButton.setText("Start Audio Intent");
    24.         finalContainer.addView(sampleButton);
    25.         setContentView(finalContainer);
    26.     }
    27.     public void onClick(View arg0) {
    28.         // TODO Auto-generated method stub
    29.         Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
    30.         startActivityForResult(intent, 1); // intent and requestCode of 1
    31.     }
    32.     @Override
    33.     protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    34.         // TODO Auto-generated method stub
    35.      
    36.         if (requestCode == 1) {
    37.               // is the resultCode OK?
    38.             if (resultCode == RESULT_OK) {
    39.                     // lets get the uri
    40.                   Uri audioUri = intent.getData();
    41.                   audioUri.toString();
    42.                     // lets play the uri or do something with it.
    43.                  // playAudio(audioUri);
    44.                 }
    45.             }
    46.     }
    47.    
    48. }
    49.  
    I am testing on Android 2.2.1 (device Samsung Galaxy POP). Am i missing out on something? Kindly help me with this.

    Thanking you,
    Regards,
    S.A.Norton Stanley
     

    Advertisement

Share This Page

Loading...