手机拍照代码示例

package com.gyarmy.takephoto;

import java.io.File;

import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.hardware.Camera;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

	
	private static final int RESULT_CODE = 100;


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


	public void takephoto(View v){
		
		Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
		File file = new File(Environment.getExternalStorageDirectory(),System.currentTimeMillis()+".jpg");
		intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
		
		startActivityForResult(intent, RESULT_CODE);
		
		
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if(RESULT_CODE == requestCode){
			switch(resultCode){
			case Activity.RESULT_OK:
				System.out.println("ok");
				break;
			case Activity.RESULT_CANCELED:
				System.out.println("cancel");
				break;
			default:
				break;
					
			}
			
		}
	}
	
}

原文链接: 手机拍照代码示例 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( https://gyarmy.com/post-151.html )

发表评论

0则评论给“手机拍照代码示例”