Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create folder in Android [duplicate]

Tags:

java

file

android

 import java.io.File;       File folder = new File(Environment.getExternalStorageDirectory() + "/TollCulator");     boolean success = true;     if (!folder.exists()) {         //Toast.makeText(MainActivity.this, "Directory Does Not Exist, Create It", Toast.LENGTH_SHORT).show();         success = folder.mkdir();     }     if (success) {         //Toast.makeText(MainActivity.this, "Directory Created", Toast.LENGTH_SHORT).show();     } else {         //Toast.makeText(MainActivity.this, "Failed - Error", Toast.LENGTH_SHORT).show();     } 

The above should create a folder in my SD card if it does not exist, if it does then don't do anything. Although the toast works based on the condition but it doesn't create a directory when it does not exist. Any idea how to resolve it?

My Manifest looks like this:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.test.testing"     android:versionCode="1"     android:versionName="1.0" >      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />      <uses-sdk         android:minSdkVersion="6"         android:targetSdkVersion="17" />      <application         android:allowBackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/AppTheme" >         <activity             android:name="com.test.testing.MainActivity"             android:label="@string/app_name" >             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                  <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>     </application>  </manifest> 

Update: I updated my manifest as well as updated my code but it's still not creating the folder in my SD card. Keep in mind, I am using Eclipse and running the app directly to my phone (GNex VZW) instead of using an AVD.

like image 637
Si8 Avatar asked Jul 22 '13 18:07

Si8


People also ask

How do I create multiple folders on android?

To do this on your device: Access the home screen panel where the apps you want to put into a folder are located. Drag the first app and drop it on top of another and this will create a folder with both apps inside. Tap the folder to view the apps in it.


1 Answers

Add this permission in Manifest,
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

File folder = new File(Environment.getExternalStorageDirectory() +                               File.separator + "TollCulator"); boolean success = true; if (!folder.exists()) {     success = folder.mkdirs(); } if (success) {     // Do something on success } else {     // Do something else on failure  } 

when u run the application go too DDMS->File Explorer->mnt folder->sdcard folder->toll-creation folder

like image 178
KOTIOS Avatar answered Oct 01 '22 17:10

KOTIOS