@Override
protected void onActivityResult(
int
requestCode,
int
resultCode, Intent data) {
super
.onActivityResult(requestCode, resultCode, data);
if
(requestCode
=
=
200
) {
Log.e(
"Rzx"
,mPicPath.toString());
mImageView.setImageURI(Uri.fromFile(mPicPath));
}
}
```
他用的是fileprovider,开始我以为是fileprovider的问题,于是,我也用了这个,发现还是不行。
于是我也调用了相机程序,发现,相机程序是可以做到的,于是我又去逆向了系统的相机程序,代码很多,但是感觉他也没做什么多余的。
后来网上查到这篇资料
https:
/
/
blog.si
-
yee.com
/
2020
/
08
/
19
/
%
E9
%
87
%
8D
%
E5
%
AD
%
A6Android
%
E4
%
B9
%
8BFileProvider
/
他说了action的问题,但是我是主动设置的。
intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
于是我抱着试一下的心态,测试了一下,还真过去了
-
第一步,修改action
```
intent
=
new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.setClassName(
"com.example.exploitapplication"
,
"com.example.exploitapplication.MainActivity"
);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uriForFile);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(intent,
200
);
```
-
第二部,给程序授予相机权限,否则会报错,Intent发不出去
接收代码
```
public void grantUriPermissions_fileprovider(Intent intent){
try
{
Uri uriForFile
=
intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
InputStream
is
=
getContentResolver().openInputStream(uriForFile);
byte[]
buffer
=
new byte[
1024
];
int
byteCount;
while
((byteCount
=
is
.read(
buffer
)) !
=
-
1
) {
Log.e(
"Rzx"
,new String(
buffer
));
}
is
.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
```