当前位置:网站首页>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
边栏推荐
- oracle-外币记账时总账余额表gl_balance变化(上)
- SSM学生成绩信息管理系统
- ssm超市订单管理系统
- 华为机试题
- ORACLE EBS接口开发-json格式数据快捷生成
- 離線數倉和bi開發的實踐和思考
- Find in laravel8_ in_ Usage of set and upsert
- 【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
- MySQL composite index with or without ID
- 一个中年程序员学习中国近代史的小结
猜你喜欢
【信息检索导论】第一章 布尔检索
User login function: simple but difficult
SSM personnel management system
腾讯机试题
MySQL无order by的排序规则因素
架构设计三原则
Proteus -- RS-232 dual computer communication
Error in running test pyspark in idea2020
Three principles of architecture design
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
随机推荐
Agile development of software development pattern (scrum)
【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
Check log4j problems using stain analysis
view的绘制机制(一)
【信息检索导论】第六章 词项权重及向量空间模型
ORACLE EBS DATAGUARD 搭建
Oracle 11g sysaux table space full processing and the difference between move and shrink
Oracle rman半自动恢复脚本-restore阶段
Three principles of architecture design
[model distillation] tinybert: distilling Bert for natural language understanding
ORACLE EBS 和 APEX 集成登录及原理分析
[Bert, gpt+kg research] collection of papers on the integration of Pretrain model with knowledge
ORACLE EBS ADI 开发步骤
Oracle apex 21.2 installation and one click deployment
华为机试题
【信息检索导论】第七章搜索系统中的评分计算
点云数据理解(PointNet实现第3步)
RMAN增量恢复示例(1)-不带未备份的归档日志
Oracle EBs and apex integrated login and principle analysis
Sparksql data skew