2012-09-04 118 views
1

我試圖寫內部存儲somethings.Open dir ..和fileoutputstream.I設法寫一個文件,但當我嘗試使用此文件,並得到一個錯誤(在Logcat沒有錯誤。當「Startactivity」部分運行時打開一個對話框。在Android設備上的對話框中寫入「有一個數據包解析錯誤」)。實際上該文件存在但我不使用該文件。我與startactivity的目標:打開將Android文件加載到Android設備的意圖。Android內部存儲錯誤

我的內部存儲路徑

mydir = getDir("mydir", MODE_WORLD_READABLE); 
filewithmydir = new File(mydir,fileName+".apk"); 
fileOutPutStream = new FileOutputStream(filewithmydir); 

寫點東西從輸入流與進度,以文件(這部分是succesfull)

byte[] data = new byte[1024]; 
    long total = 0; 
    int count; 
    while ((count = inputStream.read(data)) != -1) { 

     total += count; 
     publishProgress((int) total * 100/fileLength); 

     fileOutPutStream.write(data, 0, count); 
    } 

其使用的文件的部分

  intent.setDataAndType(Uri.fromFile(new File(mydir.getAbsolutePath()+"/incomingplus.apk")), "application/vnd.android.package-archive"); 
      startActivity(intent);// Error is here! 

我的權限

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

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

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

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

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

+0

什麼樣的錯誤?例外?你能發佈異常嗎? – sschrass

+0

什麼是錯誤? – njzk2

+0

在Logcat中沒有錯誤。當「Startactivity」部分運行時打開對話框。在對話框中寫入「存在數據包解析錯誤」。 – Serkan

回答

0

如果你打開文件的外部應用程序,它已不能訪問您的文件。 你也使用不同的變量:intentintent.setDataAndType(Uri.fromFile(new File(mydir.getAbsolutePath()+"/incomingplus.apk")), "application/vnd.android.package-archive"); startActivity(intentGuncelle);// Error is here!

+0

我編輯了intent和intentguncelle變量。實際上在代碼中都是一樣的。我在寫這裏的時候會犯錯。 – Serkan

0

intentGuncelle你有沒有列入清單的權限?

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

我編輯了我的權限。是的,我已經添加了這個權限 – Serkan

+0

你能顯示日誌嗎? – JMPergar