44import android .content .Intent ;
55import android .graphics .Color ;
66import android .os .Environment ;
7+ import android .support .v4 .app .Fragment ;
78
89import cafe .adriel .androidaudiorecorder .model .AudioChannel ;
910import cafe .adriel .androidaudiorecorder .model .AudioSampleRate ;
@@ -20,6 +21,7 @@ public class AndroidAudioRecorder {
2021 protected static final String EXTRA_KEEP_DISPLAY_ON = "keepDisplayOn" ;
2122
2223 private Activity activity ;
24+ private Fragment fragment ;
2325
2426 private String filePath = Environment .getExternalStorageDirectory () + "/recorded_audio.wav" ;
2527 private AudioSource source = AudioSource .MIC ;
@@ -34,10 +36,18 @@ private AndroidAudioRecorder(Activity activity) {
3436 this .activity = activity ;
3537 }
3638
39+ private AndroidAudioRecorder (Fragment fragment ) {
40+ this .fragment = fragment ;
41+ }
42+
3743 public static AndroidAudioRecorder with (Activity activity ) {
3844 return new AndroidAudioRecorder (activity );
3945 }
4046
47+ public static AndroidAudioRecorder with (Fragment fragment ) {
48+ return new AndroidAudioRecorder (fragment );
49+ }
50+
4151 public AndroidAudioRecorder setFilePath (String filePath ) {
4252 this .filePath = filePath ;
4353 return this ;
@@ -90,4 +100,16 @@ public void record() {
90100 activity .startActivityForResult (intent , requestCode );
91101 }
92102
93- }
103+ public void recordFromFragment () {
104+ Intent intent = new Intent (fragment .getActivity (), AudioRecorderActivity .class );
105+ intent .putExtra (EXTRA_FILE_PATH , filePath );
106+ intent .putExtra (EXTRA_COLOR , color );
107+ intent .putExtra (EXTRA_SOURCE , source );
108+ intent .putExtra (EXTRA_CHANNEL , channel );
109+ intent .putExtra (EXTRA_SAMPLE_RATE , sampleRate );
110+ intent .putExtra (EXTRA_AUTO_START , autoStart );
111+ intent .putExtra (EXTRA_KEEP_DISPLAY_ON , keepDisplayOn );
112+ fragment .startActivityForResult (intent , requestCode );
113+ }
114+
115+ }
0 commit comments