2012-10-23 85 views
1

我用下面的代码工作:创建文件并不在机器人

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

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

// *** other code *** 

但是,当应用程序到达行

f.createNewFile(); 

什么appens。其他代码行不会执行并且不会发生错误。

从哪里执行该代码被配置成在manfiest这样的活性:

<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> 

这种活性不是主要的活性,并且在清单我获得以下韦林氏:

"Exported activity does not require permission" 

这是什么意思?可能与我的创建文件问题有关?

+1

看到有:http://stackoverflow.com/questions/9931662/android-permission-denied-when-creating-a-new-file-in-external-storage – Vladimir

回答

2

您的警告与您在创建文件时遇到的问题无关。

您没有正确的权限设置写入设备上的外部存储。

添加

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

到您的清单中的<activity标签

以上如果您想了解该警告的详细信息的清单来看看这个答案here

+0

有了很高的声誉,你应该旗重复的问题。 –

+0

我已经在我的清单 – GVillani82

0

小心的/ mnt/SD卡/可能无法在所有设备上工作,您应该使用Environment.getExternalStorageDirectory()并检查清单中的权限,如评论中所述

+0

中设置了我的权限。输出文件字符串以这种方式生成: Environment.getExternalStorageDirectory()。getAbsolutePath()+“/mydir/Host4.apk”; 但是,这个检索/ mnt/sdcard/...目录 – GVillani82

相关问题