the debug to find millet in choosing pictures back road king road is not absolute, but rather FileProvider uri, so how to use this uri? Can I convert this Uri to Bitmap? If you can't give me that this Uri have what effect??
Posted on the logic code
call system album
Intent Intent;
If (Build) VERSION) SDK_INT & lt; 19) {
Intent=new intent (intent. ACTION_GET_CONTENT);
Intent. SetType (" image/* ");
} else {
Intent=new intent (intent. ACTION_PICK, android. The provider. The MediaStore. Images, Media, EXTERNAL_CONTENT_URI);
}
StartActivityForResult (intent, requestPic);
onActivityResult return
@ Override
Protected void onActivityResult (int requestCode, int the resultCode, Intent data) {
Super. OnActivityResult (requestCode, the resultCode, data);
If (requestCode==requestPic & amp; & The resultCode==Activity. RESULT_OK) {//album selection results
Photouri=data. GetData ();
StartPhotoZoom (requestPic photouri);
} else if (requestCode==requestCup & amp; & The resultCode==Activity. RESULT_OK) {//cut success
Bundle extras=data. GetExtras ();
IsNewHeadBitmap=false;
If (extras!=null) {
Photo=extras. GetParcelable (" data ");
RoundImageButtonView. SetImageBitmap (photo);
IsNewHeadBitmap=true;
}
} else if (requestCode==requestCup & amp; & The resultCode!=Activity. RESULT_OK) {//screenshot failure
IsNewHeadBitmap=false;
If (action==requestCarmela) {
if (! TextUtils. IsEmpty (bimapPath)) {
Photo=BitmapUtils. DecodeSampledBitmapFromResource (bimapPath, 320, 320);
If (photo!=null) {
RoundImageButtonView. SetImageBitmap (photo);
IsNewHeadBitmap=true;
}
}
}
}
}
cutting method
Public void startPhotoZoom (int code, Uri Uri) {
Action=code;
Intent Intent=new Intent (com. Android. Camera. The action. "CROP");
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
//intent. SetFlags (intent. FLAG_GRANT_READ_URI_PERMISSION | intent. FLAG_GRANT_WRITE_URI_PERMISSION);
//uri=FileProvider. GetUriForFile (mContext BuildConfig. APPLICATION_ID + "PIC", the new File (bimapPath));//7.0
Intent. SetDataAndType (uri, "image/*");
} the else
Intent. SetDataAndType (uri, "image/*");
//set tailoring
Intent. PutExtra (" crop ", "true");
//aspectX aspectY is wide high proportion
Intent. PutExtra (" aspectX ", 1);
Intent. PutExtra (" aspectY ", 1);
//outputX outputY is cut out pictures wide high
Intent. PutExtra (" outputX ", 320);
Intent. PutExtra (" outputY ", 320);
Intent. PutExtra (" return - data ", true);
StartActivityForResult (intent, requestCup);
}
Code posted, hope bosses door see,
CodePudding user response:
The Android 7.0 future retrieval, it is not absolutely road king, need special adaptationCodePudding user response: