为什么不在redmi note 3 6.0.1中捕获相机后在imageview中检索图像

时间:2018-03-31 11:01:02

标签: android android-camera

为什么在redmi note 3 6.0.1中捕获相机之后不能在imageView中检索图像,在图像视图中没有设置捕获但这是在三星lolipop上工作请告诉我原因和解决方案请给我我代码添加到我的代码不要给新的代码与新的matherds混淆请谢谢.....不要给新的代码与新matherds混淆请谢谢

menifest

**     

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"
    tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-feature android:name="android.hardware.camera" />

<uses-feature android:name="android.hardware.camera.autofocus" />**

表示请求权限

 private void askPersmissions(String permission,int requestCode) {
    if (ContextCompat.checkSelfPermission(this,permission)!= PackageManager.PERMISSION_GRANTED)
    {

    }

 @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {

   permissionManager.checkResult(requestCode,permissions,grantResults);
    ArrayList<String>granted=permissionManager.getStatus().get(0).granted;
    ArrayList<String>denied=permissionManager.getStatus().get(0).denied;


}

这是代码#

  camera = (ImageView) findViewById(R.id.mySelfie);
    camera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(i, CAMERA_REQUEST_CODE);
        }
    });


    btnPost.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            startPosting();
        }
    });
}

public void startPosting() {

    dialog.setMessage("submiting....");
    dialog.show();
    final String detail = WriteSomthng.getText().toString().trim();

    if (!TextUtils.isEmpty(detail) && path!=null) {


        StorageReference Randompath = referenceRandom.child("Randompath/"+ UUID.randomUUID().toString());
        Randompath.putFile(path).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                Uri downloadUrl = taskSnapshot.getDownloadUrl();
                DatabaseReference userPost = databaseRandom.push();
                userPost.child("detail").setValue(detail);
                userPost.child("username").setValue(Common.currentUser.getUsername());
                userPost.child("image").setValue(downloadUrl.toString());
                userPost.child("phone").setValue(Common.currentUser.getPhone());
                userPost.child("address").setValue(Common.currentUser.getAddress());

                Intent intent = new Intent(Home.this, AllPic.class);
                startActivity(intent);
                Toast.makeText(Home.this, "Submited", Toast.LENGTH_LONG).show();
                dialog.dismiss();

            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {

            }
        }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                double progress=(100.0*taskSnapshot.getBytesTransferred()/taskSnapshot.getTotalByteCount());
                dialog.setMessage("Submitting   "+(int)progress+"%");

            }
        });
    }

    else {
        Toast.makeText(Home.this, "Please say  something", Toast.LENGTH_LONG).show();
        dialog.dismiss();
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK && data!=null && data.getData()!=null)
    {
        path = data.getData();
        try {
            bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), path);
            camera.setImageBitmap(bitmap);
        } catch (IOException e)

        {
            e.printStackTrace();
        }

    }

0 个答案:

没有答案