2011-06-02 185 views
4

我能夠下載apk文件並將其存儲在我的/data/data/com.android.myApp/anotherApp.apk。我想知道是否有一種方法可以從另一個應用程序安裝此文件。我目前正在使用: 從另一個Android應用安裝apk而不使用SD卡

Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(filepath), "application/vnd.android.package-archive"); startActivity(intent);

這裏是我的清單文件:

當我運行這一點。它給了我「解析錯誤:解析包有問題」。我不知道問題是什麼? 1)是否需要將應用程序存儲在SD卡中?我不想那麼做 2)權限問題? 3)正在安裝損壞的軟件包?

回答

1

通常,當您將文件保存在應用程序沙箱中時,它們將保存在「文件」文件夾下。所以你完整的路徑應該是:

/data/data/com.android.myApp/files/anotherApp.apk 

如果你是在模擬器上工作,你可以做一個亞行外殼LS確認,如果該文件是居然還有:

adb shell "ls /data/data/com.android.myApp/files" 
+0

該文件在那裏。我使用Eclipse,我通過DDMS文件系統查找它。 – Abhishek 2011-06-02 20:39:30

+0

該文件存在。我擔心/ data/data目錄讀取了priveldges – Abhishek 2011-06-02 21:19:37

+0

您能否顯示構建filepath變量的代碼?在你的問題中,你似乎錯過了「/ files」元素。 – hopia 2011-06-02 22:56:33

2

您需要預先設置filepathfile://

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.parse("file://" + filepath), "application/vnd.android.package-archive"); startActivity(intent); 
1

試試這個哥們......

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(new File(path+"/yourapp.apk")), application/vnd.android.package-archive"); 
startActivity(intent);