簡體   English   中英

無法以編程方式安裝apk文件

[英]Failed to install an apk file programmatically

我以編程方式從Google雲端硬盤下載了apk文件。 每次我嘗試以編程方式安裝它時,都只會顯示諸如“尚未安裝應用程序”之類的字樣(我已將其翻譯)。 我比較了原始文件和下載文件的校驗和,以查看下載文件是否損壞,但不是。

Logcat不打印有關此的任何信息。 這是我嘗試安裝的方式:

    @Override
    public void onUpdateDownloaded(String path) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

解決了問題:我只是嘗試安裝一個較低版本的應用程序,這導致了問題。

它可能不適用於Uri.fromFile(new File(path))

首先以編程方式將apk文件復制到sd卡,然后

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM