2012-10-23 35 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

相關問題