我正在尝试制作一个可以拍摄高质量照片并上传它们的应用程序,但最重要的部分之一不起作用,即相机。意图数据为空,因此不显示图像。我从https://developer.android.com/training/camera/photobasics#TaskPath 获取了信息。我尝试了不同的方式,但没有任何效果。
package com.example.gn.nextcamtest;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
TextView txt_Test;
Button btn_Cam;
ImageView iv_image;
static final int REQUEST_IMAGE_CAPTURE = 1;
String mCurrentPhotoPath;
public static final int RequestPermissionCode = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_Cam = (Button) findViewById(R.id.btn_Cam);
iv_image = (ImageView) findViewById(R.id.iv_Test);
txt_Test = (TextView) findViewById(R.id.txt_test);
EnableRuntimePermissionToAccessCamera();
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
txt_Test.setText(" " + bundle.getString("test"));
}
btn_Cam.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dispatchTakePictureIntent();
}
});
}
相关分类