2012-07-18 55 views
1

我從服務器下載的Android應用程序,並用它保存到我的應用程序的內部空間應用:安卓:不能安裝保存到內部存儲器

URL url = new URL(Urls[0]); 
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
File outputFile = new File(getFilesDir(), "Apps"); 
outputFile.mkdirs(); 
File file = makeFilename(outputFile, _appName + ".apk"); 
file.createNewFile(); 
file.setExecutable(true); 
file.setReadable(true, false); 
file.setWritable(true, false); 
FileOutputStream fout = new FileOutputStream(zipFile); 
InputStream in = conn.getInputStream(); 
byte[] buffer = new byte[1024]; 
int length = 0; 
while ((length = in.read(buffer)) > 0) { 
fout.write(buffer, 0, length); 
} 
fout.close(); 
in.close(); 
outputFile.setExecutable(true, false); 
outputFile.setReadable(true, false); 
outputFile.setWritable(true, false); 


private File makeFilename(File base, String name) { 
     if (name.indexOf(File.separatorChar) < 0) { 
      return new File(base, name); 
     } 
     throw new IllegalArgumentException("File " + name 
       + " contains a path separator"); 
    } 

當下載完成後,將出現一個通知。當我點擊這個通知時,應該安裝該應用程序。但實際上,當我點擊通知時,出現「分析包錯誤」。我做錯了什麼?

Intent i = new Intent(Intent.ACTION_VIEW); 
i.setDataAndType(Uri.fromFile(new File(getFilesDir()+ "/Apps/_appName.apk")),"application/vnd.android.package-archive"); 
PendingIntent act = PendingIntent.getActivity(MainActivity._activity,0, i, 0); 
notification.setLatestEventInfo("TEXT", "TEXT, act); 
+0

你可以包含logcat中顯示的內容嗎? – vArDo 2012-07-18 12:40:58

+0

解析清單時出現分析錯誤。停止安裝 – 2012-07-18 12:48:49

回答

1

我對你的下載.apk文件無疑是私人您的應用程序本身。

所以只是檢查,

而且還當您存儲文件在您的應用程序確保它,WORLD_READABLE權限一樣,

Context.MODE_WORLD_READABLE

喜歡的東西,

OutputStream myOutputFile = openFileOutput("xxxx.apk", Context.MODE_WORLD_READABLE);