1

I using the following code:

 String outputFile = "/mnt/sdcard/mydir/myApp.apk"
 File f = new File(outputFile);

 if(!f.exists())
       f.createNewFile();

 // *** other code ***

But when the application reaches the line

 f.createNewFile();

nothing appens. The other code linees are not executed and no error occurs.

The activity from where I executed this code is configured in manfiest in this way:

 <activity android:theme="@android:style/Theme.NoTitleBar" 
        android:name=".ACT_ImpostazioniAvanzate"  android:screenOrientation="landscape">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="content" />
            <data android:scheme="file" />
            <data android:mimeType="application/vnd.android.package-archive" />
        </intent-filter>
    </activity>

This activity is not the main activity, and in the manifest I obtain the following Waring:

 "Exported activity does not require permission"

What does this mean? May be related to my creation file problem?

GVillani82
  • 17,196
  • 30
  • 105
  • 172
  • 1
    See there: http://stackoverflow.com/questions/9931662/android-permission-denied-when-creating-a-new-file-in-external-storage – Volodymyr Oct 23 '12 at 16:41

2 Answers2

2

Your warning is unrelated to your issue with creating files.

You don't have the proper permission set to write to the external storage on the device.

Add

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

to your manifest above the <activity tag

If you want more info about the warning in the manifest take a look at this answer here

Community
  • 1
  • 1
dymmeh
  • 22,247
  • 5
  • 53
  • 60
0

Be careful /mnt/sdcard/ may not work on all the devices, you should use Environment.getExternalStorageDirectory() and check also the permission in the manifest as said in the comments

Damien Praca
  • 3,126
  • 21
  • 14
  • I know. The outputfile string is generated in this way: Environment.getExternalStorageDirectory().getAbsolutePath() + "/mydir/Host4.apk"; But this retrievs the /mnt/sdcard/... directory – GVillani82 Oct 23 '12 at 16:59