Reputation: 41
I am new to Android and building an app that needs to save the data into a text file. I wanted to have my app folder created under Internal Storage (/storage/emulated/0/) just exactly same as for WhatsApp. I know the solution about how to FILE create to make directory. My debug console also shows the directory was created but I couldn't see either through Filemanager Or if connected to PC through USB. It is the same case when I try to save in sdcard path. My phone is not Rooted (though tried but not successful). If only possible with rooting the phone, my question is how can I see the WhatsApp folder both in Internal Storage though my phone is not rooted. I wanted to see my folder to be visible same as how I can see WhatsApp folder.
Here is my code and attaching screenshot connected USB to PC:
File root = Environment.getExternalStorageDirectory();
File mydirectory=new File(root + "/Test");
if (root.canWrite()) {
if(!mydirectory.exists()) {
mydirectory.mkdirs(); //directory is created;
Log.d("created the directory",mydirectory.toString()+"");
}
mydirectory.setExecutable(true);
mydirectory.setReadable(true);
mydirectory.setWritable(true);
MediaScannerConnection.scanFile(getContext(), new String[] {mydirectory.toString()}, null, null);
Intent mediaScannerIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri fileContentUri = Uri.fromFile(mydirectory);
mediaScannerIntent.setData(fileContentUri);
getContext().sendBroadcast(mediaScannerIntent);
}
AndroidManifest File:
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Version details-
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.saisureshc.gridlayouttest"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
Debug Console:
D/created the directory: /storage/emulated/0/Test
Attaching the screen shot after adding the code as per "user7486817"
But I see folder created doesnt look like a folder
Upvotes: 0
Views: 854
Reputation: 57
You have android.permission.WRITE_INTERNAL_STORAGE
, but you need android.permission.WRITE_EXTERNAL_STORAGE
to write to external storage
Upvotes: 2