当前位置:网站首页>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
边栏推荐
- CRP实施方法论
- ORACLE 11G利用 ORDS+pljson来实现json_table 效果
- 【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
- MapReduce concepts and cases (Shang Silicon Valley Learning Notes)
- 【Torch】解决tensor参数有梯度,weight不更新的若干思路
- Sqli-labs customs clearance (less1)
- PHP uses the method of collecting to insert a value into the specified position in the array
- Two table Association of pyspark in idea2020 (field names are the same)
- 一份Slide两张表格带你快速了解目标检测
- 【Ranking】Pre-trained Language Model based Ranking in Baidu Search
猜你喜欢
Proteus -- RS-232 dual computer communication
类加载器及双亲委派机制
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
TCP attack
ssm垃圾分类管理系统
SSM supermarket order management system
Spark SQL task performance optimization (basic)
【信息检索导论】第七章搜索系统中的评分计算
SSM实验室设备管理
[introduction to information retrieval] Chapter 3 fault tolerant retrieval
随机推荐
[paper introduction] r-drop: regulated dropout for neural networks
Ding Dong, here comes the redis om object mapping framework
【信息检索导论】第六章 词项权重及向量空间模型
【Torch】最简洁logging使用指南
叮咚,Redis OM对象映射框架来了
Find in laravel8_ in_ Usage of set and upsert
Alpha Beta Pruning in Adversarial Search
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
离线数仓和bi开发的实践和思考
[introduction to information retrieval] Chapter II vocabulary dictionary and inverted record table
oracle apex ajax process + dy 校验
架构设计三原则
MapReduce concepts and cases (Shang Silicon Valley Learning Notes)
[introduction to information retrieval] Chapter 6 term weight and vector space model
Analysis of MapReduce and yarn principles
Changes in foreign currency bookkeeping and revaluation general ledger balance table (Part 2)
DNS attack details
Sqli labs customs clearance summary-page2
Oracle RMAN semi automatic recovery script restore phase
CRP implementation methodology