当前位置:网站首页>Open failed: enoent (no such file or directory) / (operation not permitted)
Open failed: enoent (no such file or directory) / (operation not permitted)
2022-07-02 07:24:00 【Linxi, Lin Xi】
One 、Android 11 Failed to upload and download resources :open failed: ENOENT (No such file or directory)
Premise : Find out Android 11 Uploading pictures and downloading files failed , Error log :open failed: ENOENT (No such file or directory)
Turned out to be Android 11 Special permissions are required to access the file explorer :MANAGE_EXTERNAL_STORAGE File management permissions
The previous application for permission was through Dialog Show to users , and Android 11 in the future adopt Activity Show the user (Intent Jump ).
1) The goal is sdk It is amended as follows 30:targetSdkVersion 30
2) List file registration :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
3) When the system is 11 And above apply for this permission
public void checkPermissions() {
// Apply for dangerous authority
....
// apply Android11 Special privileges
requestManagerPermission();
}
private void requestManagerPermission() {
// When the system is 11 And above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Apply for permission without file management permission
if (!Environment.isExternalStorageManager()) {
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
intent.setData(Uri.parse("package:" + mContext.getPackageName()));
startActivityForResult(intent, REQUEST_MANAGER_PERMISSION);
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_MANAGER_PERMISSION && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// User denied permission , Reapply
if (!Environment.isExternalStorageManager()) {
requestManagerPermission();
}
}
}
Two 、 Failed to save screenshot :open failed: EPERM (Operation not permitted)
Premise : Find out Android 11 Failed to save screenshot , Error log :open failed: ENOENT (Operation not permitted)
solve : According to the version , Save the file in a different path .
Get external storage directory by default ,sdk>29 Get the outside SD Card cache directory .
String path = Environment.getExternalStorageDirectory().getPath();
if (Build.VERSION.SDK_INT > 29) {
path = activity.getExternalFilesDir(null).getAbsolutePath() ;
}
File file = new File(path, fileName);
// Screenshot process ... Please ignore
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
// screenshots - take view Draw it as the original
View v = activity.getWindow().getDecorView();
Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(),Bitmap.Config.RGB_565);
Canvas c = new Canvas(bitmap);
c.translate(-v.getScrollX(), -v.getScrollY());
v.draw(c);
// Compress Bitmap, I won't support it png Image compression
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
bos.flush();
bos.close();
// Insert the file into the system gallery
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, file.getAbsolutePath());
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
Uri uri =activity.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
// Notify gallery to update
activity.sendBroadcast(newIntent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
ToastUtils.showMessage(" Saved successfully ");
} catch (IOException e) {
e.printStackTrace();
ToastUtils.showMessage(e.getMessage());
}
Reference resources :https://blog.csdn.net/dongxianfei/article/details/115449709
https://zhuanlan.zhihu.com/p/477539888
边栏推荐
- spark sql任务性能优化(基础)
- parser.parse_args 布尔值类型将False解析为True
- ORACLE EBS接口开发-json格式数据快捷生成
- ERNIE1.0 与 ERNIE2.0 论文解读
- 一份Slide两张表格带你快速了解目标检测
- pySpark构建临时表报错
- Three principles of architecture design
- MySQL has no collation factor of order by
- One field in thinkphp5 corresponds to multiple fuzzy queries
- Only the background of famous universities and factories can programmers have a way out? Netizen: two, big factory background is OK
猜你喜欢
随机推荐
ARP attack
ORACLE EBS中消息队列fnd_msg_pub、fnd_message在PL/SQL中的应用
ORACLE 11G SYSAUX表空间满处理及move和shrink区别
Analysis of MapReduce and yarn principles
Oracle apex Ajax process + dy verification
ORACLE 11.2.0.3 不停机处理SYSAUX表空间一直增长问题
【Torch】解决tensor参数有梯度,weight不更新的若干思路
@Transitional step pit
Message queue fnd in Oracle EBS_ msg_ pub、fnd_ Application of message in pl/sql
Illustration of etcd access in kubernetes
Interpretation of ernie1.0 and ernie2.0 papers
点云数据理解(PointNet实现第3步)
ssm垃圾分类管理系统
叮咚,Redis OM对象映射框架来了
SSM实验室设备管理
Oracle EBS ADI development steps
Oracle RMAN semi automatic recovery script restore phase
ORACLE 11G利用 ORDS+pljson来实现json_table 效果
MySQL composite index with or without ID
Typeerror in allenlp: object of type tensor is not JSON serializable error









