Android 调用系统的拍相程序进行录像

xml:

<?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:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="前往录像"
            android:onClick="click"
            />

</LinearLayout>

java:

package com.example.usingSystemCamera;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Toast;

import java.io.File;

public class MyActivity extends Activity {

    private File file;//相片文件

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    /**
     * 界面按钮点击事件,跳转到系统录像机
     */
    public void click(View view) {
        Intent intent = new Intent();
        intent.setAction("android.media.action.VIDEO_CAPTURE");
        intent.addCategory("android.intent.category.DEFAULT");
        file = new File(Environment.getExternalStorageDirectory(), "myVideo.3gp");
        Uri uri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        startActivityForResult(intent, 0);
    }

    /**
     * 提示
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Toast.makeText(this,"录像成功!",1).show();
    }
}

 

 

posted @ 2014-04-13 15:12  无忧之路  阅读(536)  评论(0编辑  收藏  举报
无忧之路