activity的使用(十二):启动录音

package com.example.androidtest;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AndroidTest extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_android_test);
		
		Button btn = (Button)findViewById(R.id.callBtn);
		btn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				startRecording();
			}
		});
	}
	
	public void startRecording()
	{
		Intent intent = new Intent("android.provider.MediaStore.RECORD_SOUND");
		startActivityForResult(intent, 0);
	}
	
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		switch(requestCode) {
		case 0:
			if (resultCode == RESULT_OK) {
				Uri recoredAudioPath = data.getData();
				Log.v("Demo", recoredAudioPath.toString());
			}
		}
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.android_test, menu);
		return true;
	}

	
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<Button
    android:id="@+id/callBtn"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/btn"
    android:onClick="doClick"
    />
<TextView
    android:id="@+id/textView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />    
</LinearLayout>

你可能感兴趣的:(activity的使用(十二):启动录音)