data.getData()始终返回null

时间:2019-03-06 15:20:39

标签: java android android-camera

如标题中所述,data.getData()始终返回null,我无法弄清楚如何解决这个问题。我是android studio的新手,如果这是一个新手问题,我会提前道歉。

private Button imageBtn;
private ImageView imageView;
private static final int CAMERA_REQUEST_CODE = 1;
private StorageReference mStorage;
private ProgressDialog mProgress;
private File output;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);
    setContentView(R.layout.activity_camera);
    mStorage = FirebaseStorage.getInstance().getReference();
    imageBtn = (Button) findViewById(R.id.imageBtn);
    imageView = (ImageView) findViewById(R.id.imageView);
    mProgress = new ProgressDialog(this);


    imageBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (intent.resolveActivity(getPackageManager()) != null) {

                startActivityForResult(intent, CAMERA_REQUEST_CODE);
            }
        }
    });
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);


    if (requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK) {

        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView.setImageBitmap(photo);
        //Uri uri = data.getData();
        Log.i("wut ", data +"");
        Log.i("wut are u ",data.getData()+"");
    }
}

编辑:我已经尝试过link中提供的代码,但是却遇到了这个错误:java.lang.NullPointerException: file

0 个答案:

没有答案