gpt4 book ai didi

android - 如何在 WhatsApp 或 Allo 等内部存储中创建文件夹?

转载 作者:行者123 更新时间:2023-11-29 15:40:51 25 4
gpt4 key购买 nike

我的任务是将位图保存在内部存储器中。我尝试了所有方法。我无法获得所需的输出。在文件夹中创建并保存在内部设备中的文件夹数据/用户/0/数据/~~。--试过

File mediaFile = new File(c.getExternalCacheDir(), "/MaherSaad");

工作并在缓存中创建文件夹 -- android/data/com.myapp.~/cache

我想创建文件夹并显示成那样

内部存储/Myapp/newFolder

enter image description here

最佳答案

终于找到解决办法了在数据文件夹外创建一个文件夹

简单地

File mFolder = new File(Environment.getExternalStorageDirectory(), "Folder_Name");
if (!mFolder.exists()) {
boolean b = mFolder.mkdirs();

}

错误是没有处理运行时权限代码简单...

String TAG = "Permsission : ";
if (Build.VERSION.SDK_INT >= 23) {
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Log.v(TAG,"Permission is granted");
return true;
} else {

Log.v(TAG,"Permission is revoked");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
return false;
}
}
else { //permission is automatically granted on sdk<23 upon installation
Log.v(TAG,"Permission is granted");
return true;
}

处理权限

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
String TAG = "Permsission : ";
if(grantResults[0]== PackageManager.PERMISSION_GRANTED){
Log.v(TAG,"Permission: "+permissions[0]+ "was "+grantResults[0]);
//resume tasks needing this permission
//Define the path you want
File mFolder = new File(Environment.getExternalStorageDirectory(), "Folder_Name");
if (!mFolder.exists()) {
boolean b = mFolder.mkdirs();

}
}
}

关于android - 如何在 WhatsApp 或 Allo 等内部存储中创建文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40718564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com