打开相机
Posted 红领巾传递人
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了打开相机相关的知识,希望对你有一定的参考价值。
布局:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/ic_launcher"
android:id="@+id/imageView" />
<Button
android:text="拍照然后进入相册"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button" />
代码:
package com.example.my_zhengliyiixa;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import static android.app.Activity.RESULT_OK;
/**
* A simple {@link Fragment} subclass.
*/
public class Fragment_C extends Fragment implements View.OnClickListener {
// private ImageView imageView;
private Button button;
// private String sdPath;
// private String piPath;
private static int REQUEST_THUMBNALL = 1;
public Fragment_C() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_fragment__c, container, false);
// sdPath = Environment.getExternalStorageDirectory().getPath();
// piPath = sdPath +"/"+"bbt.png";
initView(view);
return view;
}
private void initView(View view) {
// imageView = (ImageView) view.findViewById(R.id.imageView);
button = (Button) view.findViewById(R.id.button);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,REQUEST_THUMBNALL);
break;
}
}
// @Override
// public void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
// if (resultCode == RESULT_OK){
// if (requestCode == REQUEST_THUMBNALL){
// Bundle bundle = data.getExtras();
// Bitmap bitmap = (Bitmap) bundle.get("data");
// imageView.setImageBitmap(bitmap);
//
//
//
// }
//
//
// }
//
//
// }
}
以上是关于打开相机的主要内容,如果未能解决你的问题,请参考以下文章