I am trying to create a folder and subfolder namely "CJI/Export" in "Internal Memory" using the following code. To ensure that the command is successfully executed, I have added Toast Messages in all states.
I tried running the code on two devices: "Redmi Note 3" & "Honor 9i".
In Redmi Note-3, I am getting the results as expected. The command is creating the folder & subfolder successfully.
But in Honor 9i, I also shows the toast message "Export Folder created successfully", but I can't see any such folder or sub-folder in the device manager (internal memory). Also, on closing the app and launching it again, I get the same toast message "Export Folder created successfully".
package com.example.app.activities;
public class HomeScreenActivity extends AppCompatActivity implements{
private String dirPathExport;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_screen);
dirPathExport= createMediaDirExport(HomeScreenActivity.this);
}
public static String createMediaDirExport(Context context) {
String dirPath="";
try {
dirPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/CJI/Export";
File dir_temp = new File(dirPath);
if (!dir_temp.exists()) {
dir_temp.mkdirs();
Toast.makeText(context, "Export Folder created successfully", Toast.LENGTH_SHORT).show();
}
Toast.makeText(context, "Export Folder already present", Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
e.printStackTrace();
Toast.makeText(context, "Error during folder creation", Toast.LENGTH_SHORT).show();
}
return dirPath;
}
}
Expected Result is to get the folder in Internal Memory in Honor 9i