标签:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.lenovo.service.XiangjiActivity" android:orientation="vertical"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="bt_1" android:text="相机"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="bt_2" android:text="录像机"/> </LinearLayout>
package com.example.lenovo.service;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import java.io.File;
public class XiangjiActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xiangji);
}
public void bt_1(View v)
{
Intent intent=new Intent();
intent.setAction("android.media.action.IMAGE_CAPTURE");
intent.addCategory("android.intent.category.DEFAULT");
File file=new File(Environment.getExternalStorageDirectory()+"/000.jpg");
Uri uri=Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
this.startActivity(intent);
}
public void bt_2(View v)
{
Intent intent=new Intent();
intent.setAction("android.media.action.VIDEO_CAPTURE");
intent.addCategory("android.intent.category.DEFAULT");
File file=new File(Environment.getExternalStorageDirectory()+"/000.3gp");
Uri uri=Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
this.startActivity(intent);
}
}
标签:
原文地址:http://www.cnblogs.com/1ming/p/5643127.html