Search code examples
androidfileandroid-activityandroid-manifestcreation

Creation file does not work in android


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?


Solution

  • 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