Home > Mobile >  The small white this string of code what is the problem? Why not call system camera, stored images..
The small white this string of code what is the problem? Why not call system camera, stored images..

Time:12-26

Click a button to enter this method, the following is the code:
Private void takePhoto () {
//initializes the image path
Intent Intent=new Intent (MediaStore. ACTION_IMAGE_CAPTURE);
The File File=new File (getExternalFilesDir (null) + File. The separator + "myPicture");
if(! File. The exists ()) {
file.mkdirs();
}
String pictureName=new SimpleDateFormat (" yyyyMMddHHmmss "). The format (new Date ()) + ". JPG ";
The File saveFile=new File (File, pictureName);
Uri=FileProvider. GetUriForFile (this, "univ. Buaa. Icabinet. The activity", saveFile);
Intent. PutExtra (MediaStore EXTRA_OUTPUT, uri);//according to this uri to save photos
StartActivityForResult (intent, REQUEST_CODE_CAMERA);//the results back to your onActivityResult function
}
@ Override
Protected void onActivityResult (int requestCode, int the resultCode, Intent data) {
If (the resultCode==RESULT_OK & amp; & RequestCode=={REQUEST_CODE_CAMERA)
Toast. MakeText (this, "save the photos success", Toast. LENGTH_SHORT), show ();
Bitmap Bitmap=(Bitmap) Objects. RequireNonNull (data) getExtras ()), get (" data ");
Picture_of_object. SetImageBitmap (bitmap);
}
Super. OnActivityResult (requestCode, the resultCode, data);
}}
Have withered

CodePudding user response:

By the way, my FileProvider filepath_data. XML is so write:
<? The XML version="1.0" encoding="utf-8"?>

I really looked through the Internet information

CodePudding user response:

Can't is what meaning, what is the log information,
Additional permissions have? The sdcard card reads to dynamic application permissions in new project by default, unless you change the target API

CodePudding user response:

The second row is the code not,,,
Emmm permissions I use Rxpermission ", and should not is a question of authority, because I don't store photos of code can open the camera,,,

CodePudding user response:

Now already know that is a question of uri=null, excuse me everybody may be what reason, is the file path is wrong, please

CodePudding user response:

You try this paragraph is added in the intent:
If (Build) VERSION) SDK_INT & gt;=Build. VERSION_CODES. N) {
Intent. AddFlags (intent. FLAG_GRANT_READ_URI_PERMISSION);//add it said temporary authorized the Uri of the target application represent file
}
  • Related